tasayco@phoenix.Princeton.EDU (Maria Tasayco) (10/08/90)
I wrote a simple program to find out how much free memory is there in
the heap (or the largest available chunk), at least I hoped that would
be the result! Instead I found that it returns a much smaller value
(my setup is an Atari 1040ST with 1MB and around 430kB of free memory
when Minix boots up): it returns consistently 56kB. I looked into the
source for sbrk() and it looked OK. Maybe this behaviour is to be
expected but I don't see why.
The program is short and follows:
#include <stdio.h>
#define ulong unsigned long
extern char *sbrk();
int main()
{
char *tp, *tp0, *tp1;
long top = 0;
/* Get memory top (at least that's what I think it should do) */
tp0 = sbrk((int)0);
/* Try to get 1kB until no more available */
while ((tp = sbrk((int)1024)) != (char *)-1) tp1 = tp;
/* Show the result */
printf("free memory = %ldkb\n", ((ulong)tp1 - (ulong)tp0)/1024);
return(0);
}
Any comments are welcome (even if they tell me how dump I am).
Francisco Figueirido
e-mail: tasayco@phoenix.princeton.edu
adrie@philica.ica.philips.nl (Adrie Koolen) (10/08/90)
In article <3189@idunno.Princeton.EDU> tasayco@phoenix.Princeton.EDU (Maria Tasayco) writes: >I wrote a simple program to find out how much free memory is there in >the heap (or the largest available chunk), at least I hoped that would >be the result! Instead I found that it returns a much smaller value >(my setup is an Atari 1040ST with 1MB and around 430kB of free memory >when Minix boots up): it returns consistently 56kB. I looked into the >source for sbrk() and it looked OK. Maybe this behaviour is to be >expected but I don't see why. In Minix, every program gets a specified amount of memory. The gap, that your ST compiler normally assigns to a process, is probably 64KB. 56KB of this gap is reported to you by your program. To increase the amount of memory, your program gets, use the `chmem' program: chmem =200000 program and run your program again. It should now report some 189KB of available memory. Adrie Koolen (adrie@ica.philips.nl) Philips Innovation Centre Aachen