[New-bugs-announce] [issue2898] Add memory footprint query

Robert Schuppenies report at bugs.python.org
Sat May 17 12:44:31 CEST 2008

New submission from Robert Schuppenies <okkotonushi at googlemail.com>:

I propose a patch which allows to query the memory footprint of an
object. Calling 'footprint(o)', a python developer can retrieve the
size of any python object. Only the size of the object itself will be
returned, the size of any referenced objects will be ignored.

The patch implements a generic function to compute the object
size. This works in most, but a few cases. One of these exceptions is
the dictionary with its particular table implementation. Such cases
can be handled by implementing an optional method in C. This would
also be the case for third-party implementations with unusual type

One advantage with this approach is that the object size can be
computed at the level an object is allocated, not requiring complex
computations and considerations on higher levels.

I am not completely happy with the name 'footprint', but think using
'sizeof' would be confused with plain 'size', and 'memory_usage' was
somewhat too long to be typed conveniently.

Current test pass on linux32 and linux64, but the test suite is not
complete, yet.

This patch is part of my Google Summer of Code project on Python
memory profiling
Also, this is my first patch, so please let me know where missed
something, did not follow coding conventions, or made wrong

components: Interpreter Core
files: footprint.patch
keywords: patch
messages: 66989
nosy: okkoto
severity: normal
status: open
title: Add memory footprint query
type: feature request
versions: Python 2.6
Added file: http://bugs.python.org/file10353/footprint.patch

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list