Now I've got a database, which area type is a range of byte.

Now I've got a bit of memory, or perhaps an object. How you can convert this bit of memory as well as an item to some byte array and to ensure that I'm able to keep byte array towards the database.

Imagine that the object is

Foo foo

The memory is

buf         (actually, don't know how to declare it yet)

The database area is

byte data[256]

Only hex value like x'1' could be place in to the area.

Thanks a lot!

You will find two techniques.

The first is simple but has serious restrictions. You are able to write the memory picture of the Foo object. The drawback is when you alter the compiler or even the structure of Foo then all of your data may no more loadable (since the image no more matches the item). To get this done simply employ


because the byte array.

Another technique is known as 'serialization'. You can use it when the object changes but adds much space to scribe the data. Should you have only 256 bytes then you definitely have to be careful serialization does not produce a string too big in order to save.

Boost includes a serialization library you might want to take a look at, though you will need to careful about how big the objects produced. If you are only carrying this out having a small group of classes, you might want to write the marshalling and unmarshalling functions yourself.

In the documentation:

"Here, we make use of the term "serialization" to mean the reversible deconstruction of the arbitrary group of C++ data structures to some sequence of bytes. "