[issue14520] Buggy Decimal.__sizeof__

Martin v. Löwis report at bugs.python.org
Mon Apr 9 18:30:25 CEST 2012


Martin v. Löwis <martin at v.loewis.de> added the comment:

> In the C version of decimal, do distinct Decimal objects ever share  
> coefficients?  (This would be an obvious optimization for methods  
> like Decimal.copy_negate;  I don't know whether the C version  
> applies such optimizations.)  If there's potential for shared  
> coefficients, that might make the "not count any memory twice" part  
> tricky.

I know of three strategies to deal with such a case:
a) expose the inner objects, preferably through tp_traverse, and
    don't account for them in the container,
b) find a "canonical" owner of the contained objects, and only
    account for them along with the canonical container.
c) compute the number N of shared owners, and divide the object
    size by N. Due to rounding, this may be somewhat incorrect.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14520>
_______________________________________


More information about the Python-bugs-list mailing list