
Robert Ramey
This example should probably be
ar << binary_object(i + 1, p); // etc
Robert Ramey
Basilevs wrote:
On Sat, Aug 30, 2008 at 11:12 AM, Robert Ramey
wrote: I'm suspecting that there is a confusion about how to seriailzation a pointer to a null terminated string. It's natural to want to do something like
char *p; ... p = "jsdkfjads" ... ar & p;
because the library syntax encourages one to think that way.
But in this case, one would want
save(... int i = strlen(p); ar << i; ar << binary_object(i, p); }
load(... int i; ar >> i; ar >> binary_object(i,p); }
How do we deal with the trailing null? In this example trailing null is not saved, and it is a good thing, but shouldn't we add it after loading?
Thank you for laying this out, it is exactly what I need. Is there a way to do this in a free serialize function rather than requiring save & load functions? I would like to write a serialize function for each of my structures up through the hierarchy, and it looks to me like if I write save/load functions for a structure in the middle then I will have to continue with that all the way through to the top. So I would like to be able to handle the null terminated string within the serialize function if that's possible. Thanks, Diane