[Numpy-discussion] Aligned array allocations

Sturla Molden sturla.molden at gmail.com
Thu Jan 22 10:24:20 EST 2015


Antoine Pitrou <solipsis at pitrou.net> wrote:

> By always using an aligned allocator there is some overhead:
> - all arrays occupy a bit more memory by a small average amount
>   (probably 16 bytes average on a 64-bit machine, for a 16 byte
>   guaranteed alignment)

NumPy arrays are Python objects. They have an overhead anyway, much more
than this, and 16 bytes are not worse than adding a couple of pointers to
the struct. In the big picture this tiny overhead does not matter.

> - array resizes can be more expensive in CPU time, when the physical
>   start changes and its alignment changes too

We are using Python. If we were worried about small inefficiencies we would
not be using it. Resizing ndarrays are rare anyway. They are not used like
Python lists or instead of lists. We use lists in the same way as anyone
else who uses Python. So an ndarray resize can afford to be more espensive
than a list append.

Also the NumPy community expects an ndarray resize to be expensive and O(n)
due to its current behavior: If an array has a view, realloc is out of the
question.

:-) 

Sturla




More information about the NumPy-Discussion mailing list