Note that there are some explanatory texts on larger screens.

plurals
  1. POstrange malloc behavior with Doug Lea allocator
    text
    copied!<p>I have an very small system with only 16kb of heap, no mmap, no swap. I'm using the latest version 2.8.5 of Doug Lea allocator <a href="ftp://g.oswego.edu/pub/misc/malloc-2.8.5.c" rel="nofollow">ftp://g.oswego.edu/pub/misc/malloc-2.8.5.c</a></p> <p><strong>UPDATE I made a smaller test case that is easier to understand and see what is my problem</strong></p> <p>If I allocate 8kb, free it, allocate 12kb, it's working (i != NULL), I can allocate the 12 kb:</p> <pre><code>char *i; dlstats(); i = dlmalloc(8192); printf("DEBUG: %p\n", i); dlstats(); dlfree(i); dlstats(); i = dlmalloc(12288); printf("DEBUG: %p\n", i); dlstats(); dlfree(i); dlstats(); </code></pre> <p>displays:</p> <pre><code>heap 0xa00003f0 sbrk 0xa00003f0 arena 0 ordblks 0 usmblks 0 uordblks 0 fordblks 0 keepcost 0 DEBUG: 0xa00003f8 heap 0xa00003f0 sbrk 0xa0002440 arena 8272 ordblks 1 usmblks 8272 uordblks 8200 fordblks 72 keepcost 32 heap 0xa00003f0 sbrk 0xa0002440 arena 8272 ordblks 1 usmblks 8272 uordblks 0 fordblks 8272 keepcost 8232 DEBUG: 0xa00003f8 heap 0xa00003f0 sbrk 0xa0003460 arena 12400 ordblks 1 usmblks 12400 uordblks 12296 fordblks 104 keepcost 64 heap 0xa00003f0 sbrk 0xa0003460 arena 12400 ordblks 1 usmblks 12400 uordblks 0 fordblks 12400 keepcost 12360 </code></pre> <p>If I first allocate a too big buffer (30kb) and then I allocate 8kb, free it, allocate 12kb, it's working (i == NULL), i <em>cannot</em> allocate the 12 kb:</p> <pre><code>char *i; dlstats(); i = dlmalloc(30000); printf("DEBUG: %p\n", i); dlstats(); i = dlmalloc(8192); printf("DEBUG: %p\n", i); dlstats(); dlfree(i); dlstats(); i = dlmalloc(12288); printf("DEBUG: %p\n", i); dlstats(); dlfree(i); dlstats(); </code></pre> <p>displays:</p> <pre><code>heap 0xa00003f0 sbrk 0xa00003f0 arena 0 ordblks 0 usmblks 0 uordblks 0 fordblks 0 keepcost 0 DEBUG: 0x0 heap 0xa00003f0 sbrk 0xa00003f0 arena 0 ordblks 0 usmblks 0 uordblks 0 fordblks 0 keepcost 0 DEBUG: 0xa00003f8 heap 0xa00003f0 sbrk 0xa0002430 arena 8256 ordblks 1 usmblks 8256 uordblks 8200 fordblks 56 keepcost 16 heap 0xa00003f0 sbrk 0xa0002430 arena 8256 ordblks 1 usmblks 8256 uordblks 0 fordblks 8256 keepcost 8216 DEBUG: 0x0 heap 0xa00003f0 sbrk 0xa0002430 arena 8256 ordblks 1 usmblks 8256 uordblks 0 fordblks 8256 keepcost 8216 heap 0xa00003f0 sbrk 0xa0002430 arena 8256 ordblks 1 usmblks 8256 uordblks 0 fordblks 8256 keepcost 8216 </code></pre> <p>At every moment, only one allocation is made and freed before allocation another block so the memory should never be fragmented.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload