Hello All,
I am trying to convert structures to Byte stream(Serialization). I have one concept,

Now I am converting each structure object to char pointer, but for structures with pointers this logic wont applicable.

can any one help me with any logic for serialization in C/C++

>can any one help me with any logic for serialization in C/C++
There's not just one way to do it. How you serialize a structure depends on the type and contents of your structure. But an easy (and verbose) way is to save the contents as a delimited string:

struct t {
  char *name;
  char *addr;
  long int zip;
} foo;

char packed[APPROPRIATE_SIZE];

sprintf ( packed, "%s|%s|%ld", foo.name, foo.addr, foo.zip );

>can any one help me with any logic for serialization in C/C++
There's not just one way to do it. How you serialize a structure depends on the type and contents of your structure. But an easy (and verbose) way is to save the contents as a delimited string:

struct t {
  char *name;
  char *addr;
  long int zip;
} foo;

char packed[APPROPRIATE_SIZE];


sprintf ( packed, "%s|%s|%ld", foo.name, foo.addr, foo.zip );

Hi Narue,
Thanks for u r immediate reply.

Hi Narue,
Thanks for u r immediate reply.

Hello Narue,
Do u have any other logic, since i need to fill the structures with data upto 2 to 20Mb, in this case memory will become a problem.

Thanks and Regrads
Nagendra R

>i need to fill the structures with data upto 2 to 20Mb, in this case memory will become a problem.
It sounds like you're relying too much on massive in-core storage when you should be thinking smarter and processing smaller chunks of data incrementally. But if you must have objects up to 20 megs, then the best way to serialize is with a lossless compression scheme. But that's no longer the issue if keeping the uncompressed data in fast memory is impractical.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.