member variable alignment in __gc class?

B

Bae,Hyun-jik

Is member variable alignment in __gc class same to that of __nogc class?
For example, does this code below make problems?(Please ignore other errors
such as wrong grammar ,etc.)

Please reply. Thanks in advance.

Regards,
Hyun-jik Bae

--------------

public __gc class Vector3
{
int x,y,z;
void CopyFromPtr();
}

Foo()
{
int data[3];
FillSomeData(data);

Vector3 __pin *vec={a valid object};

memcpy(&vec->x,data,sizeof(int)*3);
}
 
T

Tomas Restrepo \(MVP\)

Is member variable alignment in __gc class same to that of __nogc class?

Not necessarily, and, by default, I wouldn't count on it. It depends on a
lot of things, specially in the object layout (look at the docs for
StructLayoutAttribute for details).
For example, does this code below make problems?(Please ignore other
errors such as wrong grammar ,etc.)

I'd avoid doing that for many reasons. First of all, it is very unsafe, both
in what the runtime denominates unsafe code, and in reality. one false move,
and you might very well end up corrupting the entire manage heap and
possibly crashing the .NET runtime or trashing the garbage collector. NOT a
place you want to be in :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top