In the wonderful world of C# i can create a memory stream without specifying its size,
write into it and then just take the underlying buffer.
How can i do the same in c++? basicly i need to do:
memory_stream ms(GROW_AS_MUCH_AS_YOU_LIKE);
ms << someLargeObjects << someSmallObjects << someObjectsWhosSizeIDontKnow;
unsigned char* buffer = ms.GetBuffer();
int bufferSize = ms.GetBufferSize();
rawNetworkSocket.Send(buffer, bufferSize);
By the way I have boost in my project though I’m not all that familiar with it.
Thank you.
Using this approach you will have to parse the result where you receive it (as the code above just transforms your data into an unstructured string.
Another problem with it is that since C++ doesn’t support reflection, you will have to define operator << for your objects. This is the code for a
Customclass:If you want structured serialization, have a look at boost::serialization.