Hi!
I have a custom data type that need to store some raw data blocks, at CustomDataTypeClass::WriteData()
. Each memory block has an integer id/index and may be read in a different order as saved, so instead of using HyperFile::WriteMemory()
, I'm using HyperFile::WriteContainer()
, with BaseContainer::SetMemory()
setting each id/block pair. The API reference for BaseContainer::SetMemory()
says this about the memory pointer:
mem: The memory buffer. The container takes the ownership over the memory buffer.
I usually assumes that the BaseContainer creates it's own copy of the data it stores, and owns it. If we store an Int32, it will internally create a GeData with the value. Doesn't it apply to memory too? If I use SetMemory(), will it alloc a copy of the buffer internally in a GeData ank keep it until it's destroyed? That ownership statement got me worried, sounds like the BaseContainer just saves the pointer and takes ownership of the buffer I'm passing to it, instead of allocating new buffer to store. If that's the case, after storing the BaseContainer to the HyperFile, when it's destroyed it will free my original buffer, with bad consequences. Should I allocate a new buffer before storing? In that scenario, will it be stored in the project file?
Same question applies for GeData, it's not clear if GeData::SetMemory()
will allocate a new block or just take ownership of the buffer.