Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7175707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:21:30+00:00 2026-05-28T16:21:30+00:00

The different size of memory allocation is observed during the object creation on class

  • 0

The different size of memory allocation is observed during the object creation on class C below,

class C {
 int i;
 int j;
};

void f() {
 C *c = new C;
 C *c2 = new C[2];
 C (*c3)[2] = new C[2][2];
}

c is allocated with 8 bytes;

c2 is allocated with 8*2+4 bytes;

c3 is allocated with 8*2*2+4 bytes.

Why does c2 and c3 aquire 4 more bytes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:21:31+00:00Added an answer on May 28, 2026 at 4:21 pm

    Remember that C++ separates memory allocation and object expression. The default array-new expression T * p = new T[N]; both allocates enough memory for N objects and constructs those objects. At the other end, delete[] p; must call the destructor of all those elements, and then free the memory.

    While allocating and freeing memory is handled by the platform, and freeable memory is sufficiently well identified to the OS by a single pointer value, constructing and destroying objects is more complicated. The number of actual objects must be stored somewhere, and to that end, the standard permits a C++ implementation to request more memory than N * sizeof(T). It is true that the pointer p will always point to the beginning of the array of N objects, but p does not have to be the same pointer that was returned by the underlying memory allocator. (In fact, p is guaranteed to be precisely the value of the underlying allocation result offset by the excess amount of memory.)

    The details are entirely left up to the implementation. Some platforms provide additional guarantees, though; for example, the Itanium ABI (which calls the extra data “array cookie”) says that the memory for new T[N] will be laid out as follows:

    +- alignof(T) --+-- sizeof(T) --+-- sizeof(T) --+-- sizeof(T) --+-- ...
    | ***** [8B: N] |  1st element  |  2nd element  |  3rd element  |  .....
    +---------------+---------------+---------------+---------------+-- ...
    A               A
    |               |_ result of "new T[N]"
    |
    |_ value returned "operator new[]()"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between void *bytes = alloca(size); and char bytes[size]; //Or to
I have a question about different versions of an object, their sizes, and allocation.
int d; cin >> d; int asdf[d]; Is this considered dynamic memory allocation? According
In my project i used image array with 16+16 32+32 48+48 128+128 different size
What is the best practice/solution to maintain fonts size with different screen resolutions?
My requirements are that Ads have a definite size, could be different media types
I have a question regarding using intptr_t vs. long int . I've observed that
GIVEN that you have a fixed area of memory already allocated that you would
We see a size difference here when building our application in VC 2008 Express
Is there a difference in double size when I run my app on 32

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.