Re: array allocaton size

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 06/25/04


Date: Fri, 25 Jun 2004 14:11:26 GMT

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.

Is that 'sizeof(fred) * 2'?

> 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?

Some compiler-/OS-specific dynamic memory allocation information
is stored there, perhaps. Why do you care?

> The platform is VC++ .NET 2003 in debug mode if it makes any
> difference...

You might want to ask in microsoft.public.vc.language if you need
to know more about VC++'s memory manager.

V



Relevant Pages

  • array allocaton size
    ... This may be a dumb question, but I've searched the FAQ ...
    (comp.lang.cpp)
  • Re: wrong print
    ... you must be using non-standard libraries. ... int max_line_len = 1024; char **Amm,**Pss; ... char* readline; void scandir; ... Before posting for the first time to a group ALWAYS read the FAQ ...
    (comp.lang.c)
  • Re: malloc for members of a structure and a segmentation fault
    ... almost the entire FAQ, but can't seem to figure out this problem. ... and a pointer to a character pointer */ ... int main { ... void test; ...
    (comp.lang.c)
  • Re: [C] structures
    ... > struct student { ... > int main ... char grade; ... a.c.l.l.c-c++ FAQ mirror: http://nullptr.merseine.nu:8080/acllcc++.html ...
    (alt.comp.lang.learn.c-cpp)
  • Re: variadic arithmetic, boolean operators
    ... containers (lists, vectors, arrays, etc.) to each function. ... int sum(int * array_of_integers, ... C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: ... Other sites: http://www.josuttis.com -- C++ STL Library book http://www.sgi.com/tech/stl -- Standard Template Library ...
    (comp.lang.c)