Rev 171: Better value for MemObjectCollection.__sizeof__ in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
John Arbash Meinel
john at arbash-meinel.com
Thu Jul 29 17:28:45 BST 2010
At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
------------------------------------------------------------
revno: 171
revision-id: john at arbash-meinel.com-20100729162825-p8n20h3zq758gjiz
parent: john at arbash-meinel.com-20100729161504-cmu4ojjqsxripnvo
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Thu 2010-07-29 11:28:25 -0500
message:
Better value for MemObjectCollection.__sizeof__
We need to track the actual _MemObject entries, too.
-------------- next part --------------
=== modified file 'meliae/_loader.pyx'
--- a/meliae/_loader.pyx 2010-07-29 16:03:15 +0000
+++ b/meliae/_loader.pyx 2010-07-29 16:28:25 +0000
@@ -643,7 +643,8 @@
cdef _MemObject *cur
cdef long my_size
my_size = (sizeof(MemObjectCollection)
- + (sizeof(_MemObject**) * (self._table_mask + 1)))
+ + (sizeof(_MemObject**) * (self._table_mask + 1))
+ + (sizeof(_MemObject) * self._active))
for i from 0 <= i <= self._table_mask:
cur = self._table[i]
if cur != NULL and cur != _dummy:
=== modified file 'meliae/tests/test__loader.py'
--- a/meliae/tests/test__loader.py 2010-07-29 16:03:15 +0000
+++ b/meliae/tests/test__loader.py 2010-07-29 16:28:25 +0000
@@ -209,19 +209,35 @@
# 3 4-byte int attributes
self.assertSizeOf(4+1024, moc, extra_size=3*4, has_gc=False)
+ def test__sizeof__one_item(self):
+ moc = _loader.MemObjectCollection()
+ # We also track the size of the referenced _MemObject entries
+ # Which is:
+ # 1: PyObject *address
+ # 2: PyObject *type_str
+ # 3: long size
+ # 4: *child_list
+ # 5: *value
+ # 6: *parent_list
+ # 7: ulong total_size
+ # 8: *proxy
+ moc.add(0, 'foo', 100)
+ self.assertSizeOf(4+1024+8, moc, extra_size=3*4, has_gc=False)
+
def test__sizeof__with_reflists(self):
moc = _loader.MemObjectCollection()
# We should assign the memory for ref-lists to the container. A
# ref-list allocates the number of entries + 1
+ # Each _memobject also takes up
moc.add(0, 'foo', 100, children=[1234], parent_list=[3456, 7890])
- self.assertSizeOf(4+1024+2+3, moc, extra_size=3*4, has_gc=False)
+ self.assertSizeOf(4+1024+8+2+3, moc, extra_size=3*4, has_gc=False)
def test__sizeof__with_dummy(self):
moc = _loader.MemObjectCollection()
moc.add(0, 'foo', 100, children=[1234], parent_list=[3456, 7890])
moc.add(1, 'foo', 100, children=[1234], parent_list=[3456, 7890])
del moc[1]
- self.assertSizeOf(4+1024+2+3, moc, extra_size=3*4, has_gc=False)
+ self.assertSizeOf(4+1024+8+2+3, moc, extra_size=3*4, has_gc=False)
class Test_MemObjectProxy(tests.TestCase):
More information about the bazaar-commits
mailing list