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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:21:08+00:00 2026-05-12T10:21:08+00:00

GetMem allows you to allocate a buffer of arbitrary size. Somewhere, the size information

  • 0

GetMem allows you to allocate a buffer of arbitrary size. Somewhere, the size information is retained by the memory manager, because you don’t need to tell it how big the buffer is when you pass the pointer to FreeMem.

Is that information for internal use only, or is there any way to retrieve the size of the buffer pointed to by a pointer?

  • 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-12T10:21:09+00:00Added an answer on May 12, 2026 at 10:21 am

    It would seem that the size of a block referenced by a pointer returned by GetMem() must be available from somewhere, given that FreeMem() does not require that you identify the size of memory to be freed – the system must be able to determine that, so why not the application developer?

    But, as others have said, the precise details of the memory management involved are NOT defined by the system per se…. Delphi has always had a replaceable memory manager architecture, and the “interface” defined for compatible memory managers does not require that they provide this information for an arbitrary pointer.

    The default memory manager will maintain the necessary information in whatever way suits it, but some other memory manager will almost certainly use an entirely different, if superficially similar, mechanism, so even if you hack a solution based on intimate knowledge of one memory manager, if you change the memory manager (or if it is changed for you, e.g. by a change in thesystem defined, memory manager which you perhaps are using by default, as occurred between Delphi 2005 and 2006, for example) then your solution will almost certainly break.

    In general, it’s not an unreasonable assumption on the part of the RTL/memory manager that the application should already know how big a piece of memory a GetMem() allocated pointer refers to, given that the application asked for it in the first place! 🙂

    And if your application did NOT allocate the pointer then your application’s memory manager has absolutely no way of knowing how big the block it references may be. It may be a pointer into the middle of some larger block, for example – only the source of the pointer can possibly know how it relates to the memory it references!

    But, if your application really does need to maintain such information about it’s own pointers, then it could of course easily devise a means to achieve this with a simple singleton class or function library through which GetMem()/FreeMem() requests are routed, to maintain a record of the associated requested size for each current allocated pointer. Such a mechanism could then of course easily expose this information as required, entirely reliably and independently of whatever memory manager is in use.

    This may in face be the only option if an “accurate” record is required , as a given memory manager implementation may allocate a larger block of memory for a given size of data than is actually requested. I do not know if any memory manager does in fact do this, but it could do so in theory, for efficiency sake.

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

Sidebar

Related Questions

I use AllocMem/GetMem/New routines to allocate memory, then use FreeMem/Dispose routines to release memory.
I am allocating the memory with GetMem (1028 bytes length), so I have an
I'm prototyping with FastMM powered Delphi 2010 and every time i allocate memory with
I have a simple record type. I allocate an new instance of this record
I am building a report from information received from a muti-select form element in
What is the difference between System.GetMem and System.ReallocMem? Delphi 2009 Help for ReallocMem, is
I have a weird problem and I don't know where I am doing wrong.
The following code does not compile, saying error C2248: 'A::getMe' : cannot access private
I have a Delphi 7 dll that exports the following function: function StringTest(var StringOut
The question more or less says it all. Given the following record structure: type

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.