[fpc-pascal]Issues regarding available memory
Alan Mead
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
size=44000000 (storage=352000000)
getmem() was successful
..[lots of dots]..OK
size=48400000 (storage=387200000)
Runtime error 216 at 0x0804EB61
0x0804EB61
0x0804E730
0x08052263
0x080480B0
0x00000000
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,
perferrably).
Thanks!
-Alan Mead
-------------------------------------------
[amead at alan ian]$ cat dummy.pas
program dummy;
type
longarray = array[0..0] of real;
var p:pointer;
l : ^longarray;
size, storage : longint;
i,j:longint;
done:boolean;
begin
writeln('Total heap available is ',MemAvail,' bytes');
writeln('Largest block available is ',MaxAvail,' bytes');
done := false;
size := 40000000;
repeat
size := round(size * 1.1);
storage := size * sizeof(real);
writeln('size=',size,' (storage=',storage,')');
getmem(l,storage);
if (l=nil) then
begin
done := true;
end
else
begin
writeln('getmem() was successful');
j := 0;
for i := 1 to size do
begin
inc(j);
if (j MOD 100000 = 0) then
begin
write('.');
j := 0;
end;
l^[i] := 1.0;
end;
writeln('OK');
freemem(l,storage);
end;
until (done);
end.
=====
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.
http://search.yahoo.com
More information about the fpc-pascal
mailing list