Goal : Have a buffer (fixed size) of memory in which I can store any type of structs. Initialized to 0s
Question : How would it work?
Here is what I was thinking up to now.
void Main()
{
void* BufferHead = CreatBuffer(1024)
}
void* CreateBuffer(int ByteCount)
{
void* Head = operator new (std::size_t(ByteCount));
memset(Head, 0, ByteCount);
return Head;
}
void* AddAt(int ByteIdx, void* DataToAdd, size_t DataSize )
{
return memcpy(BufferHead + ByteIdx, DataToAdd, DataSize);
}
void RemoveAt(int ByteIdx, size_t DataSize)
{
memset(BufferHead+ByteIdx, 0, DataSize);
}
I did't do any of the "memory fragmentation/management" nor the smart pointer to reset ptr to null. I'd like to start with a solid add add/remove/alloc interface.
EDIT:
Intend purpose of this question is to allow me to store various data types (struct, basic types, objects) of different size in a sequential way so that I can read it forward and backward in a cache friendly way as it will be "processed" between 30 and 60 times a second. I was thinking of iterating through the buffer with a Double Linked List of Node and simply put all the data where it fits at any time in the buffer.
I can use up to c++ 14 features.