Controlling memory allocation

cwoolf at mac.com cwoolf at mac.com
Mon Sep 5 10:16:36 EDT 2005


Good to know that works :)

Did you also do the same for free and realloc to keep up with your
accounting?

The more I thought about it, the more I realized that calls to other
library functions could cause address space expansion if that code
internally called malloc or mmap.

See, I can use the OS to limit stack and data segment growth, but on OS
X/Darwin, it seems malloc uses mmap instead of brk to get more memory,
so setting a ulimit on the data segment doesn't work, because
technically the data segment doesn't grow during a malloc.  Setting a
ulimit on the RSS (resident set size) doesn't work either as that limit
seems to only limit the number of pages the process is allowed to touch
(keep resident in memory) and the address range is still allowed to
expand.

Chad

Tommy.Ryding at gmail.com wrote:
> Hello.
> I have done the thing you are requesting. You can easily create your
> own memory pool and have Python to use it.
>
> I added some rows to Pyconfig.h:
>
> #ifdef malloc
> #undef malloc
> #endif /*malloc*/
> #define malloc  Python_malloc
> 
> Then I have some overhead in my own Python_malloc(size_t nBytes)




More information about the Python-list mailing list