This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年02月19日 20:28 by loewis, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| sizeof.diff | loewis, 2012年02月19日 20:28 | review | ||
| Messages (6) | |||
|---|---|---|---|
| msg153726 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2012年02月19日 20:28 | |
The cElementTree Element currently returns an incorrect response to sys.getsizeof, as it doesn't account for the extra structure, and for the child pointers array. This patch corrects the computation. |
|||
| msg162980 - (view) | Author: Eli Bendersky (eli.bendersky) * (Python committer) | Date: 2012年06月16日 17:21 | |
Out of curiosity, why don't the constituents of Element (i.e. the tag, the attributes dict, etc.) count for its size? |
|||
| msg162985 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2012年06月16日 18:43 | |
__sizeof__ is supposed to account for just the object, not for the size of any object it refers to. If you want to compute total memory consumption, you should get a list of all objects, and then sum up __sizeof__. If some object would also include some of its referents, there would be a danger of accounting some memory twice. |
|||
| msg163008 - (view) | Author: Eli Bendersky (eli.bendersky) * (Python committer) | Date: 2012年06月17日 03:04 | |
Martin, thanks for the explanation. The patch LGTM, then. Could it be useful to document this a bit more explicitly in the description of sys.getsizeof? The most intuitive thing to expect from it is to compute the *total* size including contained objects. So this is somewhat surprising: >>> import sys >>> sys.getsizeof([1, 2, 3]) 96 >>> sys.getsizeof([1, 2, [10] * 500]) 96 The last sentence in the doc of sys.getsizeof says: "See recursive sizeof recipe for an example of using getsizeof() recursively to find the size of containers and all their contents.", which can be taken as a hint, but maybe it could be just said straightforwardly. I.e before it, add: "Note that getsizeof returns just the memory occupied by the object itself, not any contained objects it holds references to". |
|||
| msg163024 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2012年06月17日 07:37 | |
Given how C's sizeof works, it may be debatable whether it's natural to expect that sys.getsizeof should be recursive. If you have a struct with pointers (say, char*) in C, and you do sizeof, the string length isn't considered, either. But I'm certainly fine with making this more clear. |
|||
| msg163035 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年06月17日 08:42 | |
New changeset 093dec81ea1f by Martin v. Löwis in branch 'default': Issue #14055: Add __sizeof__ support to _elementtree. http://hg.python.org/cpython/rev/093dec81ea1f |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58263 |
| 2012年06月17日 08:43:47 | loewis | set | status: open -> closed resolution: fixed |
| 2012年06月17日 08:42:08 | python-dev | set | nosy:
+ python-dev messages: + msg163035 |
| 2012年06月17日 07:37:25 | loewis | set | messages: + msg163024 |
| 2012年06月17日 03:04:18 | eli.bendersky | set | nosy:
+ ncoghlan messages: + msg163008 |
| 2012年06月16日 18:43:45 | loewis | set | messages: + msg162985 |
| 2012年06月16日 17:21:23 | eli.bendersky | set | messages: + msg162980 |
| 2012年06月16日 15:38:13 | pitrou | set | nosy:
+ eli.bendersky |
| 2012年06月16日 15:34:13 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka |
| 2012年02月20日 01:09:06 | Arfrever | set | nosy:
+ Arfrever |
| 2012年02月19日 20:32:22 | pitrou | set | versions:
+ Python 3.3 nosy: + flox components: + Library (Lib) type: enhancement stage: patch review |
| 2012年02月19日 20:28:45 | loewis | create | |