At 10:14 AM -0500 11/4/05, Reuben D. Budiardja wrote: >On Friday 04 November 2005 00:16, Jonathan Berry wrote: >> On 11/3/05, Reuben D. Budiardja <techlist@xxxxxxxxxxxxxxxxxxxxxxx> wrote: >> > Hello, >> > I have a small program that I use to check malloc. The program supposed >> > to exhaust memory (heap) from malloc, then quit.<snip> >> > However, when I run this program on my desktop: AMD64 FC 4 64-bit, the >> > program does not terminate after a while. But it grinds this machine to >> > almost to a halt, and I got page-swapping, etc. ><snip> >> > ------ kgobble.c---- >> > #include <stdio.h> >> > #include <string.h> >> > >> > main() >> > { >> > int *i; >> > int j=1; >> > char buf[15]; >> > >> > printf("Starting kgobble\n"); >> > >> > while(1) >> > { >> > i=(int *)malloc(8176 * j); >> > if (i==0) >> > { >> > write(1,"Memory exhaustion complete\n",27); >> > exit(0); >> > } >> > sprintf(buf,"%x\n",i); >> > write(1,buf,strlen(buf)); >> > bzero(buf,15); >> > j++; >> > } >> > } >> > >> > >> > RDB >> >> Hi Reuben, >> >> Question: At what value of i does the above program die when on a >> 32-bit machine? > >Did you mean the value of "j" ? "i" in this case is the memory address (which >of course varies between machines and runs). But in any case, for an example, >in my 32-bit machine, right before it terminate: >i = 0xbf403008, j = 884 ... So, although you aren't keeping track of the total allocation, the program has about 3GB of memory (j*(j+1)/2*8176 bytes) allocated when it fails. I think what is happening is that you are filling up VM space, rather than exhausting memory. As you never touch most of the memory, it never gets physical pages assigned. That is how you manage to "allocate" more memory than the amount of RAM and swap you reported. 8176 is an odd size to choose. 8192 (2^13) would have been easier to track, as VM pages are 4K. While I'm ragging, use printf() when you mean it instead of counting by hand, and I see no use in the bzero() call. ____________________________________________________________________ TonyN.:' <mailto:tonynelson@xxxxxxxxxxxxxxxxx> ' <http://www.georgeanelson.com/>