Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> When you have 512MiB of memory and your current allocation is 256MiB, where do you go?

Then you're out of luck no matter what strategy you use. Even allocating 256MiB + 1 byte won't work, because you can't deallocate the old buffer until the new one has been allocated.

> Also when your dataset allocates 64MiB up front, then chucks two bytes on the end, where do you go?

What I didn't say in the article is that for some of the Firefox examples where the buffers can get really large -- such as nsTArray -- it switches to a growth rate of 1.125 once it gets to 8 MiB. So in that case it would grow to 72 MiB.



Well the first point depends on what platform and how the kernel memory allocator is configured. It's possible to overcommit on Linux for example which is acceptable for short windows. NT will most likely tell you to go away.

Now that last point is the important one and is actually what I do which I was hoping to hear somewhere :-)


You can reserve more address space than physical memory just fine on NT. Committing beyond the amount of physical memory available will mean paging at some point, should you try and use all of it.


> Even allocating 256MiB + 1 byte won't work, because you can't deallocate the old buffer until the new one has been allocated

An allocator can (sometimes) grow the allocation in-place if there is unused space following it.


Even better, as long as you have the address space available somewhere, if the allocation is done via mmap (as some allocators do for larger allocations), the physical page can be mapped to a different address in userspace and then allocate the new pages to be adjacent in the user address space. In this way, you don't even need the room after the current allocation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: