[fpc-devel] removed MaxAvail,MemAvail,HeapSize

Jonas Maebe jonas.maebe at elis.ugent.be
Mon May 23 10:14:22 CEST 2005

On 23 mei 2005, at 02:29, Konstantin M√ľnning wrote:

>> What would you suggest to return under an OS like Windows, Mac OS X  
>> or
>> Linux? The current "free" memory of the OS? Free memory + buffer  
>> cache
>> - minimal buffer cache size enforced by the OS? The previous +
>> available swap space - "wired" (i.e., not swappable to disk) memory?
>> Just a constant? Something different possibly?
> I have written in my previous mail(s) that I think the best return 
> value
> would be the biggest value with which a getmem would be successful if
> memory conditions haven't changed inbetween.

The only way to know that is to perform getmem's with every increasing 
values until one fails.

> Most programs work most of the time except under heavy load. That's not
> a good argument.

I beg you pardon? I think the argument that most programs do not work 
well under heavy load is an extremely bad argument to encourage even 
more buggy programming.

> Please let it be the programmers choice
> what to do and how to handle this.

Only using tools that make sense, everything else would be snake oil 
(and in reality nothing would be handled).

> A compiler should be providing the
> means, not taking them away.

It should not provide known defunct means.

> Anybody writing a program knows that there
> may be flaws.

No, if you use RTL routines, you expect them to work.

> A warning (with an advice how to make it better) should
> still be the best for this.

People don't read the manual.

>         status:=GetFPCHeapStatus;
>         startmem:=status.CurrHeapUsed;
>         startmem:=memavail;
> I'm not sure if I understand it right as GetHeapStatus is not 
> documented
> well (I've found no reference for the meaning of the fields of the
> returned record) but it seems that someone repaced here memavail with
> another code which does about the same and has therefore the same flaw.

The above code is not used to check whether there's still enough free 
memory left, it's only used to calculate how much memory is used by the 

> I would hapily contribute the code for a better MemAvail/MaxAvail
> function if that's the problem. I would like to be able to use the
> latest compiler which now I definitely can't as I must have the BP7
> compatibility which is very good in 1.0.10.

You can make a unit which contains a dummy memavail and maxavail which 
always return a value of 1GB or so, then your program will also always 
work except under heavy load (if that is really what you want). There's 
no use in investing lots of time in making very complex routines to 
query all sorts of information from the OS and then have it fail in 
exactly the same circumstances as when you return a plain constant.


More information about the fpc-devel mailing list