On 2013-03-09, Roy Smith <r...@panix.com> wrote: > In article <khg6f3$cfr$1...@reader2.panix.com>, > Grant Edwards <invalid@invalid.invalid> wrote: > >> What I should have said was that there's no way to return to the OS >> memory obtained via calls to malloc() et al. > > That's true (for certain values of "et al"). > >> and those are the calls that "good" C programmers (like the >> maintainers of CPython) use. > > Well, there is mmap, which is exposed via the Python mmap module. > Python doesn't have anything like C++'s "placement new", so there's > no way to use that memory to hold generic Python objects, but you can > certainly use mmap to allocate a large chunk of memory, use it, and > then give it back to the OS.
[example] I was surprised to find that the object returned by mmap.mmap() supported file semantics (seek, tell, read, etc.) in addition to byte buffer semantics. Usually, the reason one maps a file is that one doesn't want to use file semantics (which are already supported by the file object) but wants instead to use buffer semantics. Using memmap to obtain a "returnable" chunk of memory seems a bit obtuse, since it requires creating an underlying file of appropriate size that ends up being superfluous. -- Grant Edwards grant.b.edwards Yow! I wonder if I ought at to tell them about my gmail.com PREVIOUS LIFE as a COMPLETE STRANGER? -- http://mail.python.org/mailman/listinfo/python-list