Re: array allocaton size
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 06/25/04
- Next message: Sree: "Returning const reference value from functions"
- Previous message: Jean-Michel Caricand: "Re: Web Interface for CORBA and ILOG"
- In reply to: Keith S.: "array allocaton size"
- Next in thread: Keith S.: "Re: array allocaton size"
- Reply: Keith S.: "Re: array allocaton size"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Jun 2004 12:35:18 +0200
"Keith S." wrote:
>
> This may be a dumb question, but I've searched the FAQ
> and can't find an obvious answer...
>
> Let's say I have a class e.g.
>
> class fred
> {
> public:
>
> int x;
> int y;
> };
>
> then I create an array of fred:
>
> freds = new fred[2];
>
> Now, I'd expect to have allocated 8 bytes * 2 i.e. 16 bytes.
> However, if I step through the code with a debugger I see
> that operator new is getting called with a size of 20 bytes.
> Why is this? What's the extra 4 bytes coming from?
The compiler needs to store somewhere how many elements are
in the array. This information is needed at destruction time
to call the correct number of destructors.
A simple way of doing this is: allocate a littel bit more memory
and store that information there.
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: Sree: "Returning const reference value from functions"
- Previous message: Jean-Michel Caricand: "Re: Web Interface for CORBA and ILOG"
- In reply to: Keith S.: "array allocaton size"
- Next in thread: Keith S.: "Re: array allocaton size"
- Reply: Keith S.: "Re: array allocaton size"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|