FPC: ^longint type, memory question 
Author Message
 FPC: ^longint type, memory question

suppose a variable V is declared as ^longint, and I perform a getmem twice
on V, what happens to the memory that is reserved for V with the first
getmem after the second getmem, is it freed or will you, when performing a
lot of getmems, eventually get a stack overflow?

greetings
wal



Mon, 15 Jul 2002 03:00:00 GMT  
 FPC: ^longint type, memory question
Quote:

> suppose a variable V is declared as ^longint, and I perform a getmem twice
> on V, what happens to the memory that is reserved for V with the first
> getmem after the second getmem, is it freed or will you, when

The first on is not freed. Because the specified pointer is unreliable.
But you can use reallocmem() to reallocate a block. When the pointer
passed to reallocmem is nil the the block is normally allocated.

This kind of memory leaks can easily be check using the heaptrc unit
which is automaticly included when you compile with -gh

Quote:
> performing a
> lot of getmems, eventually get a stack overflow?

Not a stackoverflow, maybe an out of memory error. But since FPC has a
growing heap you it's dependent on the amount of memory in your machine.

Peter



Tue, 16 Jul 2002 03:00:00 GMT  
 FPC: ^longint type, memory question
In article

Quote:

> suppose a variable V is declared as ^longint, and I perform a getmem twice
> on V, what happens to the memory that is reserved for V with the first
> getmem after the second getmem, is it freed or will you, when performing a
> lot of getmems, eventually get a stack overflow?

You'll get a memory leak (which won't cause a stack overflow, but it
will cause an out-of-memory error or an enormous swap file after a
while), just as you would get one when doing twice a getmem for another
pointer variable without freemem'ing first.

If you get fpc versino 0.99.14 (just released), you can use reallocmem
instead, that will save you the hassle of freemem/getmem every time.

Note that in FPC, you don't have to specify the size when doing a
freemem, so

var l: ^longint;

begin
  getmem(l,10000);
  reallocmem(l,15000);
  freemem(l);
end.

is completely legal and will free the correct size.

To everyone: the reason version 0.99.14 of FPC hasn't been widely
annoucned, is because we plan on releasing version 1.0 in a couple of
weeks, so you can save yourself the hassle of downloading it two times.

Jonas



Tue, 16 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. FPC: ^longint type, curious question

2. FPC: ^longint type

3. How to implement large numbers exceeding longint data type

4. longint to real/real to longint

5. FPC & BP- Set type problems

6. FPC and real data type

7. FPC Win32 memory mapped files for IPC

8. FPC - wasted memory...

9. FPC - wasted memory - solution ?

10. FPC Win32 memory mapped files for IPC

11. FPC, TMT, and memory usage.

12. LONGINT question

 

 
Powered by phpBB® Forum Software