diff options
author | Christian Heimes <christian@cheimes.de> | 2008-02-04 18:00:12 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-02-04 18:00:12 (GMT) |
commit | 422051a3675271e179995ad4a0f056ff94395d55 (patch) | |
tree | 3316e9503901082cc4beefbf169d8191c9838190 /Python | |
parent | a26cf9b7609fc1c08fd1a69ddf5e44dc98a70dce (diff) | |
download | cpython-422051a3675271e179995ad4a0f056ff94395d55.zip cpython-422051a3675271e179995ad4a0f056ff94395d55.tar.gz cpython-422051a3675271e179995ad4a0f056ff94395d55.tar.bz2 |
Patch #1953
I implemented the function sys._compact_freelists() and C API functions PyInt_/PyFloat_CompactFreeList() to compact the pre-allocated blocks of ints and floats. They allow the user to reduce the memory usage of a Python process that deals with lots of numbers.
The patch also renames sys._cleartypecache to sys._clear_type_cache
Diffstat (limited to 'Python')
-rw-r--r-- | Python/sysmodule.c | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 41830b9..8e27844 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -754,17 +754,6 @@ a 11-tuple where the entries in the tuple are counts of:\n\ 10. Number of stack pops performed by call_function()" ); -static PyObject * -sys_cleartypecache(PyObject* self, PyObject* args) -{ - PyType_ClearCache(); - Py_RETURN_NONE; -} - -PyDoc_STRVAR(cleartypecache_doc, -"_cleartypecache() -> None\n\ -Clear the internal type lookup cache."); - #ifdef __cplusplus extern "C" { #endif @@ -783,12 +772,44 @@ extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); } #endif +static PyObject * +sys_clear_type_cache(PyObject* self, PyObject* args) +{ + PyType_ClearCache(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(sys_clear_type_cache__doc__, +"_clear_type_cache() -> None\n\ +Clear the internal type lookup cache."); + + +static PyObject * +sys_compact_freelists(PyObject* self, PyObject* args) +{ + size_t isum, ibc, ibf; + size_t fsum, fbc, fbf; + + PyInt_CompactFreeList(&ibc, &ibf, &isum); + PyFloat_CompactFreeList(&fbc, &fbf, &fsum); + + return Py_BuildValue("(kkk)(kkk)", isum, ibc, ibf, + fsum, fbc, fbf); + +} + +PyDoc_STRVAR(sys_compact_freelists__doc__, +"_compact_freelists() -> ((remaing_objects, total_blocks, freed_blocks), ...)\n\ +Compact the free lists of ints and floats."); + static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, callstats_doc}, - {"_cleartypecache", sys_cleartypecache, METH_NOARGS, - cleartypecache_doc}, + {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS, + sys_clear_type_cache__doc__}, + {"_compact_freelists", sys_compact_freelists, METH_NOARGS, + sys_compact_freelists__doc__}, {"_current_frames", sys_current_frames, METH_NOARGS, current_frames_doc}, {"displayhook", sys_displayhook, METH_O, displayhook_doc}, |