question about memory management of classes

Hi all,

I have the following two options for realizations of a class LargeInt that is supposed to hold unlimitted in size integers.
Option 1.
1
2
3
4
5
6
7
8
9
10
11
class LargeIntUnsigned
{ 
public:
  unsigned int* Data;
  unsigned int size; 
};
class LargeInt : public LargeIntUnsigned
{ 
public:
  signed char sign;
};


Option 2. class LargeInt can also be realized as:
1
2
3
4
5
6
class LargeInt 
{ 
public:
  LargeIntUnsigned value;
  signed char sign;
};


Will the second realization consume more memory than the first?

In other words, will class LargeInt store a pointer to a separate object of type LargeInt? This means one extra pointer stored in memory, which I would like to aviod.
Another option is that class LargeInt "embeds" class LargeIntUnsigned (although it is not inheriting any of LargeIntUnsigned's methods).

Of course, the second realization is "morally" correct, since an signed integer is not "a kind of unsigned integer" which is the usual thing required when class B inherits class A.

Cheers
They will use the same amount of memory at this point.
Thanks jsmith! Cheers
Topic archived. No new replies allowed.