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 8597915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:01:48+00:00 2026-06-12T01:01:48+00:00

Why is it not possible to get the length of a buffer allocated in

  • 0

Why is it not possible to get the length of a buffer allocated in this fashion.

AType * pArr = new AType[nVariable];

When the same array is deallocated

delete [] pArr;

the runtime must know how much to deallocate. Is there any means to access the length before deleting the array. If no, why no such API is provided that will fetch the length?

  • 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-06-12T01:01:49+00:00Added an answer on June 12, 2026 at 1:01 am

    Is there any means to access the length before deleting the array?

    No. there is no way to determine that.
    The standard does not require the implementation to remember and provide the specifics of the number of elements requested through new.
    The implementation may simply insert specific bit patterns at end of allocated memory blocks instead of remembering the number of elements, and might simply lookup for the pattern while freeing the memory.
    In short it is solely an imlpementation detail.


    On a side note, There are 2 options to practically overcome this problem:

    1. You can simple use a std::vector which provides you member functions like size() or
    2. You can simply do the bookkeeping yourself.

    new atleast allocates enough memory as much as you requested.
    You already know how much memory you requested so you can calculate the length easily. You can find size of each item using sizeof.

    Total memory requested / Memory required for 1 item = No of Items
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure if this is possible, is there a way to get the
It is not possible to get iFrame ID using firefox-firebug. I want to get
Does anyone know why is it not possible to get the virtualpath when you
Can we get phone number of device in j2me? Is it possible or not?
Possible Duplicate: What are the reasons why Map.get(Object key) is not (fully) generic According
I'm new to custom attributes, so I'm wondering if it is possible to get
Possible Duplicate: Not possible to launch a file on a network using Java Desktop?
Is it not possible to utilize the zoom already supported in the iPhone 4S-camera
By default it is not possible to see .gitignore files in osx. What is
Why is not possible to initialize a property to a function when you declare

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.