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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:25:51+00:00 2026-05-11T08:25:51+00:00

What is the difference between System.GetMem and System.ReallocMem? Delphi 2009 Help for ReallocMem, is

  • 0

What is the difference between System.GetMem and System.ReallocMem?

Delphi 2009 Help for ReallocMem, is exactly the same description of GetMem. How about System.FreeMem and System.Dispose

What should I use with arrays?

type   PMemberDataList = ^TMemberDataList;   TMemberDataList = array[0..MaxClassMembers -1] of PMemberData;  var   FItems: PMemberDataList;  begin   GetMem(FItems, Value * SizeOf(Pointer));   FreeMem(FItems); end; 

or

begin   ReallocMem(FItems, Value * SizeOf(Pointer));   Dispose(FItems); end; 

SOLUTION

After people advices, I declared FItems as record type, not pointer to record, TMemberDataList as dynamic array, SetLength to (de)alloc array, New/Dispose to data

type   PMemberDataList = ^TMemberDataList;   TMemberDataList = array of PMemberData; var   Items: TMemberDataList;   Item: PMemberData;  // Add begin   Setlength(Items, 1);   New(Item);   Items[0]:= Item end;  // Remove begin   Dispose(Items[0]);   Setlength(Items, 0); end; 
  • 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. 2026-05-11T08:25:51+00:00Added an answer on May 11, 2026 at 8:25 am

    GetMem always allocates memory, FreeMem always releases/frees memory, ReallocMem may do one, the other, or both. In fact, when used properly, ReAllocMem is really the only memory management API needed. If you start with a nil pointer, and call ReAllocMem with a size > 0, then it acts like GetMem. If you call ReAllocMem with size = 0, then it acts like FreeMem. The only time it actually ‘re-allocates’ memory is if the pointer is non-nil and the size > 0.

    New and Dispose are designed to work with typed pointers or for you ‘old-skool’ folks, the older Turbo Pascal object model (the old ‘object) syntax. New and Dispose will also ensure that any typed pointer that is a reference to a managed type will properly initialize that type. For instance given the following:

    type   PMyRec = ^TMyRec;   TMyRec = record     Name: string;     Value: Variant;   end;  var   Rec: PMyRec; begin   New(Rec);   try     Rec.Name := 'TestValue';     Rec.Value := 100;     ...   finally     Dispose(Rec);   end; end; 

    New and Dispose will ensure that the Name and Value fields of the record are properly initialized and finalized or cleaned-up. New and Dispose, in the above case is equivalent to:

    GetMem(Rec, SizeOf(Rec^)); Initialize(Rec); ... Finalize(Rec); FreeMem(Rec); 

    For the example you gave, Gamecat is right, you would probably be better off using a dynamic array since they are better managed by the compiler and they also carry their own intrinsic length. With your example, you would have to separately keep track of the number of items in the array, such that wherever you passed around the array, you’d also have to pass around the currently allocate length. By using a dynamic array, all the information is kept neatly packaged together. This would allow you to iterate over the array regardless of the current length by simply doing one of the following:

    var   Member: TMemberData;   Items: array of TMemberData;   ... begin   SetLength(Items, Value);   for Member in Items do  // iterate over each element in the array   ...   for Low(Items) to High(Items) do // same as above only using std functions   ... end; 

    Finally, another reason you would probably want to use a dynamic array is that if TMemberData contained strings, variants, interfaces or other ‘managed’ types, they will be properly initialized and finalized without the need to do that manually.

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From Error.h: #define ERROR_BAD_LENGTH 24 ...not sure how that relates… May 12, 2026 at 12:47 am
  • Editorial Team
    Editorial Team added an answer The simple solution is just to use a ListBox control… May 12, 2026 at 12:47 am
  • Editorial Team
    Editorial Team added an answer Matching C-style comments in Lex/Flex or whatever is well documented:… May 12, 2026 at 12:47 am

Related Questions

What is the difference between using system() to execute a binary and using the
What is the difference between this: this.btnOk.Click += new System.EventHandler(this.btnOK_Click); and this? this.btnOk.Click +=
In terms of general operating system concepts, what is the difference between a file
What is the difference between add your imports inside the NameSpace or Outside. Is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.