Mailing List Archive

python/dist/src/Objects intobject.c,2.82,2.83
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv7261/python/Objects

Modified Files:
intobject.c
Log Message:
Just added comments, and cleared some XXX questions, related to int
memory management.


Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.82
retrieving revision 2.83
diff -C2 -d -r2.82 -r2.83
*** intobject.c 26 Apr 2002 00:53:34 -0000 2.82
--- intobject.c 28 Apr 2002 16:57:34 -0000 2.83
***************
*** 27,35 ****
(Using odd pointers to represent integers would save much space
but require extra checks for this special case throughout the code.)
! Since, a typical Python program spends much of its time allocating
and deallocating integers, these operations should be very fast.
Therefore we use a dedicated allocation scheme with a much lower
overhead (in space and time) than straight malloc(): a simple
dedicated free list, filled when necessary with memory from malloc().
*/

--- 27,42 ----
(Using odd pointers to represent integers would save much space
but require extra checks for this special case throughout the code.)
! Since a typical Python program spends much of its time allocating
and deallocating integers, these operations should be very fast.
Therefore we use a dedicated allocation scheme with a much lower
overhead (in space and time) than straight malloc(): a simple
dedicated free list, filled when necessary with memory from malloc().
+
+ block_list is a singly-linked list of all PyIntBlocks ever allocated,
+ linked via their next members. PyIntBlocks are never returned to the
+ system before shutdown (PyInt_Fini).
+
+ free_list is a singly-linked list of available PyIntObjects, linked
+ via abuse of their ob_type members.
*/

***************
*** 52,56 ****
{
PyIntObject *p, *q;
! /* XXX Int blocks escape the object heap. Use PyObject_MALLOC ??? */
p = (PyIntObject *) PyMem_MALLOC(sizeof(PyIntBlock));
if (p == NULL)
--- 59,63 ----
{
PyIntObject *p, *q;
! /* Python's object allocator isn't appropriate for large blocks. */
p = (PyIntObject *) PyMem_MALLOC(sizeof(PyIntBlock));
if (p == NULL)
***************
*** 58,61 ****
--- 65,70 ----
((PyIntBlock *)p)->next = block_list;
block_list = (PyIntBlock *)p;
+ /* Link the int objects together, from rear to front, then return
+ the address of the last int object in the block. */
p = &((PyIntBlock *)p)->objects[0];
q = p + N_INTOBJECTS;
***************
*** 976,980 ****
}
else {
! PyMem_FREE(list); /* XXX PyObject_FREE ??? */
bf++;
}
--- 985,989 ----
}
else {
! PyMem_FREE(list);
bf++;
}