M
mojumbo
I am supposed to be utilizing a function which sends data given a
message size and a void* (Typical C solution):
Send(unsigned int MsgSize, void* Data);
The problem is my structure is fragmented since I am utilizing a
pointer to hold allocated memory. What I mean is:
struct tsBob
{
int a;
char b;
bool c;
float* matrix;
}
Obviously matrix is constructed on the fly (heap). I need to place
the structure and the matrix data in contiguous memory in order to use
the Send function.
My attempt:
char* aMem;
int lnIncSize = sizeof(tsBob);
tsBob aTest;
sizeToAlloc = sizeof(tsBob) + sizeof(float)*3; // Let's assume a 2x2
matrix
aMem = new char[sizeToAlloc];
memcpy((void*)aMem, &aTest, lnIncSize);
memcpy((void*)(aMem+lnIncSize), (&aTest)+(lnIncSize),
sizeof(float)*3);
Doesn't work. The second memcpy ALWAYS copies the address of
aTest.matrix.
ANY IDEAS?
message size and a void* (Typical C solution):
Send(unsigned int MsgSize, void* Data);
The problem is my structure is fragmented since I am utilizing a
pointer to hold allocated memory. What I mean is:
struct tsBob
{
int a;
char b;
bool c;
float* matrix;
}
Obviously matrix is constructed on the fly (heap). I need to place
the structure and the matrix data in contiguous memory in order to use
the Send function.
My attempt:
char* aMem;
int lnIncSize = sizeof(tsBob);
tsBob aTest;
sizeToAlloc = sizeof(tsBob) + sizeof(float)*3; // Let's assume a 2x2
matrix
aMem = new char[sizeToAlloc];
memcpy((void*)aMem, &aTest, lnIncSize);
memcpy((void*)(aMem+lnIncSize), (&aTest)+(lnIncSize),
sizeof(float)*3);
Doesn't work. The second memcpy ALWAYS copies the address of
aTest.matrix.
ANY IDEAS?