[Numpy-discussion] Addition of a dict object to all NumPy objects

Christian Heimes lists@cheimes...
Fri Aug 15 19:30:22 CDT 2008


Robert Kern wrote:
> Yes, we know that. The concern I was addressing was the time overhead
> for creating the new dict object every time an ndarray gets
> instantiated. Most of these dict objects would be unused, so we would
> be wasting a substantial amount of time. If you push off the creation
> of the dict to the first time the user accesses it, then we're not
> wasting any time. We do realize that space for the pointer must still
> be reserved.

I'm sorry for pointing to the obvious.

I *guess* it's possible to delay the creation even further. You don't 
have to create a dict until somebody assigns a new attribute to an 
instance. It'd require some more code and you'd have to trade memory 
efficiency for slightly slower access to the additional attributes.

Please also note that CPython uses a freelist of unused dict instances. 
The default size of the dict free list is 80 elements. The allocation 
and deallocation of dicts is cheap if you can stay below the threshold.

Christian



More information about the Numpy-discussion mailing list