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

  • SEARCH
  • Home
  • 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 540443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:14:26+00:00 2026-05-13T10:14:26+00:00

Is it true that a pointer assigned to the starting address of a dynamically

  • 0

Is it true that a pointer assigned to the starting address of a dynamically allocated array does not have the information of the size of the array? So we have to use another variable to store its size for later processing the array through the pointer.

But when we free the dynamically allocated array, we don’t specify the size, instead we just “free ptr” or “delete [] ptr”. How could free or delete know the size of the array? Can we use the same scheme to avoid storing the size of the array in another variable?

Thanks!

  • 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-13T10:14:27+00:00Added an answer on May 13, 2026 at 10:14 am

    Yes, this is true.

    delete knows the size of the memory chunk because new adds extra information to the chunk (usually before the area returned to the user), containing its size, along with other information. Note that this is all very much implementation specific and shouldn’t be used by your code.

    So to answer your last question: No – we can’t use it – it’s an implementation detail that’s highly platform and compiler dependent.


    For example, in the sample memory allocator demonstrated in K&R2, this is the “header” placed before each allocated chunk:

    typedef long Align; /* for alignment to long boundary */
    
    union header { /* block header */
      struct {
        union header *ptr; /* next block if on free list */
        unsigned size; /* size of this block */
      } s;
    
      Align x; /* force alignment of blocks */
    };
    
    typedef union header Header;
    

    size is the size of the allocated block (that’s then used by free, or delete).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it true that C++ array is a const pointer in C++ ? http://www.cplusplus.com/forum/articles/10/#msg1381
Is it true that you cannot use COM Interop to expose COM properties? Everything
Is it true that the assigned final object field may still be null inside
My program have several worker threads that calling a function in a dynamically loaded
Do you have to pass delete the same pointer that was returned by new,
I guess my question should be silly but it is true that I have
Is it true, that the Asterisk always means Hey, that is a pointer! And
Is it true that the only way to handle default function arguments is through
Is it true that the smallest amount of memory that I can allocate in
is it true that Rails depend on cookies? It seems that flash is a

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.