[Numpy-discussion] numpy arrays, data allocation and SIMD alignement

David Cournapeau david at ar.media.kyoto-u.ac.jp
Tue Aug 7 02:11:52 EDT 2007

Anne Archibald wrote:
> Well, it can be done in Python: just allocate a too-big ndarray and
> take a slice that's the right shape and has the right alignment. But
> this sucks. Stephen G. Johnson posted code earlier in this thread that
> provides a portable aligned-memory allocator - it handles the freeing
> by (always) storing enough information to recover the original pointer
> in the padding space. (This means you always need to pad, which is a
> pain, but there's not much you can do about that.) 
This is indeed no rocket science, I feel a bit ashamed :) I don't see 
the problem with padding (except wasted time) ?
> His implementation
> stores the original pointer just before the beginning of the aligned
> data, so _aligned_free is free(((void**)ptr)[-1]). If you were worried
> about space (rather than time) you could store a single byte just
> before the pointer whose value indicated how much padding was done, or
> whatever.
I really don't see how space would be a problem in our situation: it is 
not like we will pad more than a few bytes; in the case it is, I don't 
see how python would be the right choice anymore anyway. I will try to 
prepare a patch the next few days, then.



More information about the NumPy-Discussion mailing list