0

I have 2D 1000:1000 grid of graph nodes which have references to their neighbors. I tried to serialize it with Boost.Serialize, but it fails with Segmentation fault (it works fine when I do it for 100:100 grid only). Also tried libnop but it doesn't support pointers at all.

What's the easiest way to conveniently serialize graphs in C++ without restructuring the graph every time you want to read/write to file?

Slaus
  • 2,086
  • 4
  • 26
  • 41
  • 2
    If it works fine for 100 nodes, but not a 1000 it's probably some mistake in the allocator code. Try tracing with GDB and running valgrind to see if you're accessing unallocated memory. Unfortunately serialising any graph datastructures that uses pointers and not offsets is not trivial. I'd say `boost.serializationg` is probably your best bet, unless you're willing to hand code a solution. – XapaJIaMnu Mar 06 '20 at 11:29
  • You seems to want to serialize a graph that is specifically a subset of a lattice graph (subset of a regular 2D mesh). Serializing it as a general graph it probably very inefficient and much more complex. Why not storing it as a 2D array with link information encoded yourself into each node? Note that Boost.Serialize support the serialization of 2D array by the way. – Jérôme Richard Mar 06 '20 at 14:43
  • @JérômeRichard thank you for your comment. Graph just starts being "looking like a 2D mesh", but eventually diverges from it. I just failed (due to `Segmentation fault`) to save diverged graph and tried original one to be surprised that it fails too. Saving/loading is needed just to simplify my algorithm development and implementing serialization shouldn't be that hard, I guess. Boost.Serialization fails almost instantly and I can't imagine any reason for it: why can't it cache 1 million pointers even for a recursive graph to completely save it. – Slaus Mar 06 '20 at 15:28

0 Answers0