I currently use this to serialize data, write it to shared memory so that another program can reconstruct it and use it:
template<typename T>
void Serialize(unsigned char* &Destination, const T &Source)
{
CopyMemory(Destination, &Source, sizeof(T));
//Destination += sizeof(T); //Not sure if to add this or not.
}
template<typename T>
void Serialize(unsigned char* &Destination, const std::vector<T> &VectorContainer)
{
size_t Size = VectorContainer.size();
Serialize(Destination, Size);
for (size_t I = 0; I < Size; ++I)
Serialize(Destination, VectorContainer[I]);
}
template<typename T>
void DeSerialize(unsigned char* &Destination, const T& Source, size_t Size)
{
CopyMemory(Destination, &Source, Size);
}
template<typename T>
void DeSerialize(std::vector<T>* &VectorContainer, const T &Source, size_t ContainerSize, size_t ByteSize)
{
VectorContainer.resize(ContainerSize);
CopyMemory(VectorContainer, &Source, ByteSize);
}
I'm not sure if my DeSerialize is correct though. The data I want to deserialize looks like: http://www.daniweb.com/software-development/cpp/threads/430518/shared-memory-objects-across-dlls
How should I Deserialize it?
I tried:
DeSerialize(ListOfFonts, Data[7], sizeof(FontChar));
return &ListOfFonts[0]; //Return a void* to my vector containing the reconstructed data.