Re: [Python-Dev] PEP 42: sizeof(obj) builtin

Raymond Hettinger <raymond.hettinger@verizon.net> wrote:
Yes, please! I have wished for this many times as I struggled to figure out which part of my program was using up too much RAM. Regards, Zooko http://zooko.com/ ^-- my web page http://mnet.sf.net/ ^-- my big, RAM-over-using, Python program

But the question is incredibly ill-defined, so it's not clear that Raymond will be able to calculate a useful answer. (See Tim's post.) --Guido van Rossum (home page: http://www.python.org/~guido/)

"GvR" == Guido van Rossum <guido@python.org> writes:
GvR> But the question is incredibly ill-defined, so it's not clear GvR> that Raymond will be able to calculate a useful answer. (See GvR> Tim's post.) We've gone through the exercise of figuring out how much memory is used by a dictionary several times in the office here. It's instructive to repeat the exercise, because it illustrates how hard it is to come up with a good answer :-). The basic dictionary structure is 132 bytes on i686, but the hash table is (usually) a separately malloced chunk of memory that contains the dict entries. The details of the actual table layout aren't of interest in dict_traverse(), which just gets the valid dict entries, but the layout would be of interest to something like sizeof(). If the sizeof() function were going to really be useful, builtin types would presumably need to define a slot to compute their size. Even this would overlook malloc overhead, which could well be nontrivial if an object contains several malloced buffers. Jeremy

But the question is incredibly ill-defined, so it's not clear that Raymond will be able to calculate a useful answer. (See Tim's post.) --Guido van Rossum (home page: http://www.python.org/~guido/)

"GvR" == Guido van Rossum <guido@python.org> writes:
GvR> But the question is incredibly ill-defined, so it's not clear GvR> that Raymond will be able to calculate a useful answer. (See GvR> Tim's post.) We've gone through the exercise of figuring out how much memory is used by a dictionary several times in the office here. It's instructive to repeat the exercise, because it illustrates how hard it is to come up with a good answer :-). The basic dictionary structure is 132 bytes on i686, but the hash table is (usually) a separately malloced chunk of memory that contains the dict entries. The details of the actual table layout aren't of interest in dict_traverse(), which just gets the valid dict entries, but the layout would be of interest to something like sizeof(). If the sizeof() function were going to really be useful, builtin types would presumably need to define a slot to compute their size. Even this would overlook malloc overhead, which could well be nontrivial if an object contains several malloced buffers. Jeremy
participants (3)
-
Guido van Rossum
-
Jeremy Hylton
-
Zooko