I am working on a DLL project in C++ for a Delphi executable. This executable has a structure like :
size
data[]
for example :
02 00 00 00 // Size
30 31 32 33 // data[0]
34 35 36 37 // Still data[0]
31 32 33 33 // data[1]
33 33 33 33 // Still data[1]
I tried by doing a class like :
class LittleList
{
private:
int32_t size;
DataType* data;
}
and it gives me this :
02 00 00 00 // Size
xx xx xx xx // Pointer to data (and obviously, there are data[0] and data[1] at this address)
That is not what I want.
I can achieve my goal by using an array :
class LittleList
{
private:
int32_t size;
DataType data[2];
}
but then, I am forced having a fixed length, that is still not what I want.
I thought about a dirty solution :
class LittleList
{
private:
char* data;
// Storing size at data[0] ~ data[3]
// and the actual data from data[4] to data[...]
}
but it would be really hard to parse, read and write.
Is there any clean solution for such a problem ?
By the way it is not a XY problem