Re: __malloc_init_space (example)
Laurent Bercot <[email protected]>
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
> Aftter free(x); free(y); "x" and "y" are zeroed in x_space and > available again for malloc/calloc/realloc. This is the same as malloc > first gets one page with mmap and then it shares it for small pages. Ah, you mean that the static buffer should be managed by malloc() just like a mmapped page, so the chunks of memory allocated in the static buffer can be freed and later reused. I'm still not convinced. ;) What your idea basically achieves is move the first allocated page from the heap to the static memory. That would be useful if static memory were somehow "cheaper" than heap memory. But it's not. Quite the contrary: heap memory can be reclaimed by the system, whereas static memory cannot. DJB's goal in alloc.c was not to avoid using heap memory. It was to avoid malloc() entirely and be able to give the guarantee that some of his programs did not dynamically allocate memory *at all*. Your idea only saves one mmap() call when a program allocates very little memory, at the expense of making one page unreclaimable by the system. mmap() is cheap. I don't think it's a good trade-off. -- Laurent