[fpc-pascal]Issues regarding available memory
cubrewer at yahoo.com
Fri May 16 16:49:15 CEST 2003
I need to handle arbitrarily-large datafiles. So I need to detect
the amount of memory available at run-time. I want my code to run on
Linux and Windows.
Given that the heap grows, how can I determine the maximum available
memory (in a platform-independent way)?
I thought I would GetMem() until it reports nil but that does not
apparently work... Or I am confused about the cause of error 216.
(Or I made a dumb mistake. :) When I compile my code (below) using
FPC 1.0.4 and run it on my Linux machine, I see:
[amead at alan ian]$ ./dummy
Total heap available is 262128 bytes
Largest block available is 262128 bytes
getmem() was successful
..[lots of dots]..OK
Runtime error 216 at 0x0804EB61
Also, I have a performance question: there is a noticable difference
in the time between printing these periods. Am I forcing the Linux
machine to use virtual memory? If so, is there a way to know when
I've done that (a way that will work under Windows and Linux,
[amead at alan ian]$ cat dummy.pas
longarray = array[0..0] of real;
l : ^longarray;
size, storage : longint;
writeln('Total heap available is ',MemAvail,' bytes');
writeln('Largest block available is ',MaxAvail,' bytes');
done := false;
size := 40000000;
size := round(size * 1.1);
storage := size * sizeof(real);
if (l=nil) then
done := true;
writeln('getmem() was successful');
j := 0;
for i := 1 to size do
if (j MOD 100000 = 0) then
j := 0;
l^[i] := 1.0;
A Congressman was once asked about his attitude toward whiskey. "If you mean the demon drink that poisons the mind, pollutes the body, desecrates family life, and inflames sinners, then I'm against it. "
"But if you mean the elixir of Christmas cheer, the shield against winter chill, the taxable potion that puts needed funds into public coffers to comfort little crippled children, then I'm for it."
"This is my position, and I will not compromise."
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
More information about the fpc-pascal