[BGL][Serialization] Reading a graph from a binary file: "vector subscript out of range error" and portability
Hi all,
I am trying to read a graph from a binary file. This file was
previously generated by constructing a graph consisting of 1000
vertices and almost 10M edges. While vertices are properly loaded, I
encountered a "vector subscript out of range error" when edges are
being loaded in adj_list_serialize.hpp, line 97
(boost::tie(e,inserted) = add_edge(verts[u], verts[v], graph);). At
this line, u and v are all in the order of millions, whereas I only
have 1000 vertices. When I ran the program without debugging, it
consumed the whole memory.
I put a not-so-minimal working code at the end of my e-mail. Could
somebody please point out any mistake in my code?
FYI, I use Boost 1.52, Visual C++ 2010, Windows 7 64-bit.
BTW, my aim is to generate save files which are fast to be read and
can be read on different computers. I am aware that while this binary
format can be processed fast, it is not portable. Can somebody please
tell me how non-portable it is? If there are only a few things to be
considered, for example architectural difference (32 vs 64-bit), it is
fine as I only need to generate two files for one graph. But, if there
are many of such factor, to the point that it is impossible to provide
numerous save files, is there any equally fast format which is more
portable?
Thank you!
Best regards,
Nicholas Mario Wardhana
//======================= CODE ===================================//
#include
Nicholas Mario Wardhana wrote:
int main()
//std::ofstream filename1("binary_serialization.txt"); // error - open in binary mode std::ofstream filename1("binary_serialization.txt", std::ios::binary); boost::archive::binary_oarchive binary_oa(filename1); binary_oa & g; filename1.close(); }
On 6 February 2013 00:13, Robert Ramey
Nicholas Mario Wardhana wrote:
int main()
//std::ofstream filename1("binary_serialization.txt"); // error - open in binary mode std::ofstream filename1("binary_serialization.txt", std::ios::binary); boost::archive::binary_oarchive binary_oa(filename1); binary_oa & g; filename1.close(); }
Thank you very much Robert! As the resulting file looked "binary" enough to me, I didn't realise that I missed the std::ios::binary flag when saving the file. Your code solved the problem. As for the portability, I found that there are a few affecting factors, e.g. different variable sizes and processor architectures [1]. However, I just generated the files on an another computer with similar system, and the files are exactly the same as what I previously generated on my computer. The other computer can read the file properly. As I don't target too different architectures, I think I am going to check myself to what extend the binary format is portable. Best regards, Nicholas Mario Wardhana References: [1] http://www.eskimo.com/~scs/cclass/int/sx3b.html
Nicholas Mario Wardhana wrote:
As for the portability, I found that there are a few affecting factors, e.g. different variable sizes and processor architectures [1]. However, I just generated the files on an another computer with similar system, and the files are exactly the same as what I previously generated on my computer. The other computer can read the file properly. As I don't target too different architectures, I think I am going to check myself to what extend the binary format is portable.
Just want to re-iterate that binary archives will generally not be portable. You might want to look at portable_binary_?archive Robert Ramey
Best regards, Nicholas Mario Wardhana
References: [1] http://www.eskimo.com/~scs/cclass/int/sx3b.html
On 7 February 2013 00:21, Robert Ramey
Just want to re-iterate that binary archives will generally not be portable. You might want to look at portable_binary_?archive
Robert Ramey
Thanks for your suggestion, Robert. I have just heard about portable_binary_archive, so I will look into that. Best regards, Nicholas Mario Wardhana
participants (2)
-
Nicholas Mario Wardhana
-
Robert Ramey