In gcc one can use the function "mallinfo()" in order to know, among other things, the amount of dynamic storage currently allocated by the program through "malloc()". I use it to check for program memory leaks.
I would like to know whether there is anything similar for gpc?
-- Tomasz Kowaltowski
On Fri, Mar 16, 2001 at 08:13:40AM -0300, Tomasz Kowaltowski wrote:
In gcc one can use the function "mallinfo()" in order to know, among other things, the amount of dynamic storage currently allocated by the program through "malloc()". I use it to check for program memory leaks. I would like to know whether there is anything similar for gpc?
I didn't find mallinfo in the info file of gpc, but you can use this:
program test; type mallocinfo = array [0..9] of integer; var Mi : mallocinfo; j : Integer; function Mallinfo : mallocinfo; asmname 'mallinfo';
begin Mi:=Mallinfo; for j:=0 to 9 do writeln(j, ') ->', Mi[j]) end.
I don't know if this is what you expected, because I never used this function and the results are different from C.
Eike
Eike Lange wrote:
On Fri, Mar 16, 2001 at 08:13:40AM -0300, Tomasz Kowaltowski wrote:
In gcc one can use the function "mallinfo()" in order to know, among other things, the amount of dynamic storage currently allocated by the program through "malloc()". I use it to check for program memory leaks. I would like to know whether there is anything similar for gpc?
I didn't find mallinfo in the info file of gpc, but you can use this:
AFAICS, it's a function in glibc and apparently a few other systems' libc, but not available on all systems. Using GCC/GPC does not mean using glibc, of course, so you can't assume it to be present.
If it is present and you want to use it, fine (Eike showed a way how to), otherwise, as The Chief mentioned, `AllocMemSize' and `AllocMemCount' in the System provide some of the information mallinfo() does, though they have a little runtime overhead, but if it's only for debugging, this shouldn't matter.
Either way, you'll find that a few memory blocks are allocated beyond your control. The Run Time System uses them, e.g. to keep track of opened files, finalization routines, etc.
BTW, for a quite primitive memory leap checking, you can use the included HeapMon unit. Just put `uses HeapMon;' in your program, and at the end of the program, the unit will complain if any pointers were not deallocated. It does quite the same as `AllocMemCount' and has the same runtime overhead. Since it initializes itself in its initializer and checks the memory in its finalizer (and finalizers are run in the opposite order as initializers), there should be no memory allocated for finalizers or open files (provided you closed all your files), i.e. no "false alarms"...
Frank
It works, but if I use the directive "--borland-pascal", the compiler complains about the declaration:
function Mallinfo : mallocinfo; asmname 'mallinfo';
Is there is any way around this problem?
Thanx,
-- Tomasz
Eike Lange wrote:
On Fri, Mar 16, 2001 at 08:13:40AM -0300, Tomasz Kowaltowski wrote:
In gcc one can use the function "mallinfo()" in order to know, among other things, the amount of dynamic storage currently allocated by the program through "malloc()". I use it to check for program memory leaks. I would like to know whether there is anything similar for gpc?
I didn't find mallinfo in the info file of gpc, but you can use this:
program test; type mallocinfo = array [0..9] of integer; var Mi : mallocinfo; j : Integer;
function Mallinfo : mallocinfo; asmname 'mallinfo';
begin Mi:=Mallinfo; for j:=0 to 9 do writeln(j, ') ->', Mi[j]) end.
I don't know if this is what you expected, because I never used this function and the results are different from C.
Eike
On 27 Mar 2001, at 7:40, Tomasz Kowaltowski wrote:
It works, but if I use the directive "--borland-pascal", the compiler complains about the declaration:
function Mallinfo : mallocinfo; asmname 'mallinfo';
Borland Pascal does not understand "asmname".
Is there is any way around this problem?
Why do you need to use the --borland-pascal switch? GPC should be able to cope with BP code without using that switch. However, if you do need to use the switch, you might try this;
{$gnu-pascal} function Mallinfo : mallocinfo; asmname 'mallinfo'; {$borland-pascal} <-- I am not sure if this exists!
Best regards, The Chief --------- Prof. Abimbola Olowofoyeku (The African Chief) Author of Chief's Installer Pro for Win32 Email: African_Chief@bigfoot.com http://www.bigfoot.com/~african_chief/