array allocaton size

From: Keith S. (false_at_ntlworld.com)
Date: 06/25/04


Date: Fri, 25 Jun 2004 11:17:51 +0100

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 platform is VC++ .NET 2003 in debug mode if it makes any
difference...

- Keith



Relevant Pages

  • Re: array allocaton size
    ... > This may be a dumb question, but I've searched the FAQ ... > int x; ... Some compiler-/OS-specific dynamic memory allocation information ...
    (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)