James Kanze
9/25/2008 2:01:00 PM
On Sep 25, 2:36 pm, mojumbo <jnbben...@gmail.com> wrote:
> On Sep 25, 5:03 am, James Kanze <james.ka...@gmail.com> wrote:
> > > 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.
> > You probably need more than that. Presumably, the Send
> > function sends the data somewhere, and that somewhere
> > expects a specific format. You have to respect that format.
> I'm working in a VERY tightly closed environment and I'm
> guaranteed same compiler, OS, architecture, etc.
Same compiler version, same compile options? You'll never
upgrade the system? (Or you can throw out the data if you do.)
> > > 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.
> > Already, the first one has just copied the internal bit image of
> > the data. Which probably won't work, due to a number of
> > considerations. Before going any further, you have to specify
> > the format which the data should have; functions like Send,
> > which take a void* (or a char* or an unsigned char*) require
> > that you pre-format the data to the desired format.
> Pre-format the data? That is the purpose of the struct no?
A struct doesn't have anything to do with formatting.
> or maybe I'm misunderstanding your comment. Also why wouldn't
> a copy of the internal bit image work?
Because it's not a defined format. It changes with the compiler
version or the options used to invoke the compiler. It will
change the day you upgrade the system.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34