c - missing [heap] section in /proc/pid/maps -


i'm experimenting simple c program keeps allocating memory:

for ( = 0; < 10000; ++ ) {     array[i] = malloc( 1024*1024 );     if ( array[i] == null )     {         break;     }     printf("sleeping...%d\n", i);     sleep( 60 ); } 

full code pasted here: http://tny.cz/2d9cb3df

however, when cat /proc/pid/maps, no [heap] section. why?

08048000-08049000 r-xp 00000000 08:11 17         /data/a.out 08049000-0804a000 r--p 00000000 08:11 17         /data/a.out 0804a000-0804b000 rw-p 00001000 08:11 17         /data/a.out 0804b000-0805e000 rw-p 00000000 00:00 0  b74c6000-b75c8000 rw-p 00000000 00:00 0  b75c8000-b7775000 r-xp 00000000 08:01 3539272    /lib/i386-linux-gnu/libc-2.17.so b7775000-b7777000 r--p 001ad000 08:01 3539272    /lib/i386-linux-gnu/libc-2.17.so b7777000-b7778000 rw-p 001af000 08:01 3539272    /lib/i386-linux-gnu/libc-2.17.so b7778000-b777b000 rw-p 00000000 00:00 0  b7797000-b779a000 rw-p 00000000 00:00 0  b779a000-b779b000 r-xp 00000000 00:00 0          [vdso] b779b000-b77bb000 r-xp 00000000 08:01 3539289    /lib/i386-linux-gnu/ld-2.17.so b77bb000-b77bc000 r--p 0001f000 08:01 3539289    /lib/i386-linux-gnu/ld-2.17.so b77bc000-b77bd000 rw-p 00020000 08:01 3539289    /lib/i386-linux-gnu/ld-2.17.so bff21000-bff42000 rw-p 00000000 00:00 0          [stack] 

since you're talking /proc/pid/maps assume you're on linux.

this man malloc tells me on linux distribution happen run:

normally, malloc() allocates memory heap, , adjusts size of heap required, using sbrk(2).

when allocating blocks of memory larger mmap_threshold bytes, glibc malloc() implementation allocates memory private anonymous mapping using mmap(2). mmap_threshold 128 kb default, adjustable using mallopt(3).

allocations performed using mmap(2) unaffected rlimit_data resource limit (see getrlimit(2)).

if want see [heap] in /proc/pid/maps allocate less 128k per call malloc.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -