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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:17:25+00:00 2026-05-25T22:17:25+00:00

I suspect the answer to my question is language specific, so I’d like to

  • 0

I suspect the answer to my question is language specific, so I’d like to know about C and C++. When I call free() on a buffer or use delete[], how does the program know how much memory to free?

Where is the size of the buffer or of the dynamically allocated array stored and why isn’t it available to the programmer as well?

  • 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-25T22:17:26+00:00Added an answer on May 25, 2026 at 10:17 pm

    The heap keeps track of all memory blocks, both allocated and free, specifically for that purpose. Typical (if naive) implemenation allocates memory, uses several bytes in the beginning for bookkeeping, and returns the address past those bytes. On subsequent operations (free/realloc), it would subtract a few bytes to get to the bookkeeping area.

    Some heap implementations (say, Windows’ GlobalAlloc()) let you know the block size given the starting address. But in the C/C++ RTL heap, no such service.

    Note that the malloc() sometimes overallocates memory, so the information about mallocated block size would be of limited utility. C++ new[]’ed arrays, that’s a whole another matter – for those, knowing exact array size is essential for array destruction to work properly. Still, there’s no such thing in C++ as a dynamic_sizeof operator.

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

Sidebar

Related Questions

I have a question for which I suspect the answer is a bit complex.
Simple question, not sure what the best answer is although I suspect it involves
I suspect there is an easy answer for this question but I can't find
I think the answer to my question is Yes, but i just would like
I've notice an issue - it feels like a bug but I suspect a
I'm pretty much stuck with a question I never got an answer for, a
Before someone shouts out the answer, please read the question through. What is the
I use: window.print(); to print documents. Problem: As you guys know that browsers automatically
I know this question is a duplicate of Execute method on startup in spring
I have a question about inner-workings of Python sub-interpreter initialization (from Python/C API) and

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.