Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pointer Q

Posted on 2001-06-07
7
Medium Priority
?
134 Views
Last Modified: 2010-04-06
Let's say, I define this:

type TMyRecord = record
      SomeString: String[255];
      AnotherOne: String[255];
      AnInteger: Integer;
     end;
type PMyRecord = ^TMyRecord;

what's the best way to use this?

So far I use:

var pmr: PMyRecord;
begin
  GetMem(pmr, SizeOf(TMyRecord));
  //Do my Stuff
  FreeMem(pmr, SizeOf(pmr));
end;

Now where's the difference to using

New(pmr);
Dispose(pmr);

Regards,
Oli
0
Comment
Question by:Oli2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Accepted Solution

by:
Cesario earned 150 total points
ID: 6163285
Hi Oli,

Example :

Type
  MyBuffer = Array[1..5000] of Byte;

VAR
 Buffer = ^MyBuffer;


Begin
  New(Buffer );    // reserve 5000 Byte for the Buffer
 

  GetMem ( Buffer,100);   // reserve only 100 byte for the buffer
 
 
End;
0
 
LVL 1

Author Comment

by:Oli2
ID: 6163294
okay, got that.

What about my code, I'm not sure if it's right to
set the Size to SizeOf(TMyRecord) at GetMem() and
to set it to SizeOf(pmr) at FreeMem().

Is that okay, or would it be better to set the Size
to SizeOf(TMyRecord) at FreeMem() also?

Regards,
Oli
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6163311
Hi Oli2,

Just use new and dispose.

I use GetMem, Ich I receive a Packet via Socket, and the Size of this packet is smaller than the buffer.
So I dont need to allocate 50000 byte.

Best Regards

Cesario
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 17

Expert Comment

by:geobul
ID: 6163351
Hi Oli,
The right way is to free as much memory as you have got. So:

GetMem(pmr, SizeOf(TMyRecord));
...
FreeMem(pmr, SizeOf(TMyRecord));

Regards, Geo
0
 
LVL 1

Author Comment

by:Oli2
ID: 6163369
thanx for your help.
I accept Cesario's comment as an answer since he was the first to post a comment and he answered my first question about the difference between GetMem() and New().
But also thanx to you, Geo, I hope it's okay to you that I give Cesario the points.

Regards,
Oli
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6163382
Thanx for the points ;.)
0
 
LVL 17

Expert Comment

by:geobul
ID: 6163426
Yes, it's OK.
Regards, Geo
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question