Pep wrote:
Quote:
I'm getting weird results at the moment so thought I'd rebase my
knowledge of c++ storage with your help :)
>
I have a class used as a type in a struct and the struct is handled by
a 3rd party binary writed for persistent storage. I am confused by the
results I am getting and am not sure how the 3rd party writer is
seeing the size of the stuct.
>
class foo
// I have not included the methods for brevity
{
public:
unsigned short shortArray[4];
};
It makes a difference what kind of "methods" this class has. If it
doesn't have user-defined constructors, or virtual functions, it's
most likely a POD class, which means it's safe to use 'memcpy' on it.
Quote:
typedef struct
{
foo fooVar;
char charArray[8];
} bar;
Tell us, why do you do the wicked typedef dance here? Why don't you
simply write
struct bar
{
foo fooVar;
char charArray[8];
};
?
Quote:
>
So if you do a sizeof(foo) you get back 8 as a result
OK, so your 'short' is 2 bytes long, most likely.
Quote:
and a
sizeof(bar) returns 16.
It seems that the compiler adds no padding in the 'bar' objects.
Quote:
However the class foo has methods as well.
Again, depends on what methods those are.
Quote:
Now
if I was to do any form of binary copy on bar such as using memcpy for
example using the sizeof(bar) as the length, will I definitely be
copying the complete data in bar or will the operation be thrown out
by things like internal members in foo created by the compiler, like
the vtbl in foo?
If sizeof(foo) == sizeof(short[4]), there are no "internal members"
with which you need to concern yourself.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask