comparison Python/sysmodule.c @ 45143:8fdd6d62ea55 legacy-trunk

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
author Christian Heimes <christian@cheimes.de>
date Mon, 04 Feb 2008 18:00:12 +0000
parents c05ee77b39f2
children 99355baa748d
comparison
equal deleted inserted replaced
45142:f03955faffb4 45143:8fdd6d62ea55
752 8. generator calls\n\ 752 8. generator calls\n\
753 9. All other calls\n\ 753 9. All other calls\n\
754 10. Number of stack pops performed by call_function()" 754 10. Number of stack pops performed by call_function()"
755 ); 755 );
756 756
757 static PyObject *
758 sys_cleartypecache(PyObject* self, PyObject* args)
759 {
760 PyType_ClearCache();
761 Py_RETURN_NONE;
762 }
763
764 PyDoc_STRVAR(cleartypecache_doc,
765 "_cleartypecache() -> None\n\
766 Clear the internal type lookup cache.");
767
768 #ifdef __cplusplus 757 #ifdef __cplusplus
769 extern "C" { 758 extern "C" {
770 #endif 759 #endif
771 760
772 #ifdef Py_TRACE_REFS 761 #ifdef Py_TRACE_REFS
780 #endif 769 #endif
781 770
782 #ifdef __cplusplus 771 #ifdef __cplusplus
783 } 772 }
784 #endif 773 #endif
774
775 static PyObject *
776 sys_clear_type_cache(PyObject* self, PyObject* args)
777 {
778 PyType_ClearCache();
779 Py_RETURN_NONE;
780 }
781
782 PyDoc_STRVAR(sys_clear_type_cache__doc__,
783 "_clear_type_cache() -> None\n\
784 Clear the internal type lookup cache.");
785
786
787 static PyObject *
788 sys_compact_freelists(PyObject* self, PyObject* args)
789 {
790 size_t isum, ibc, ibf;
791 size_t fsum, fbc, fbf;
792
793 PyInt_CompactFreeList(&ibc, &ibf, &isum);
794 PyFloat_CompactFreeList(&fbc, &fbf, &fsum);
795
796 return Py_BuildValue("(kkk)(kkk)", isum, ibc, ibf,
797 fsum, fbc, fbf);
798
799 }
800
801 PyDoc_STRVAR(sys_compact_freelists__doc__,
802 "_compact_freelists() -> ((remaing_objects, total_blocks, freed_blocks), ...)\n\
803 Compact the free lists of ints and floats.");
785 804
786 static PyMethodDef sys_methods[] = { 805 static PyMethodDef sys_methods[] = {
787 /* Might as well keep this in alphabetic order */ 806 /* Might as well keep this in alphabetic order */
788 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, 807 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
789 callstats_doc}, 808 callstats_doc},
790 {"_cleartypecache", sys_cleartypecache, METH_NOARGS, 809 {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,
791 cleartypecache_doc}, 810 sys_clear_type_cache__doc__},
811 {"_compact_freelists", sys_compact_freelists, METH_NOARGS,
812 sys_compact_freelists__doc__},
792 {"_current_frames", sys_current_frames, METH_NOARGS, 813 {"_current_frames", sys_current_frames, METH_NOARGS,
793 current_frames_doc}, 814 current_frames_doc},
794 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, 815 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
795 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, 816 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
796 {"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc}, 817 {"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc},