[Numpy-discussion] NumPy re-factoring project

Sturla Molden sturla@molden...
Sat Jun 12 21:39:03 CDT 2010


Den 13.06.2010 02:39, skrev David Cournapeau:
>
> But the point is to get rid of the python dependency, and if you don't
> allow any api call to allocate memory, there is not much left to
> implement in the core.
>
>    

Memory allocation is platform dependent. A CPython version could use 
bytearray, other platforms could e.g. use arrays from a gc managed heap 
(IronPython, Jython). Because memory management is platform dependent, 
it does not naturally belong in the core.

Having ndarrays allocate buffers with malloc() and "own" buffers they've 
allocated complicate things terribly. The purpose of "ownership" is to 
know which ndarray is to call free() on the buffer. Why go through all 
that pain? It's just a duplication of Python's garbage collection. 
Re-inventing the wheel is stupid. Let buffers be Python objects that 
clean themselves up.

If NumPy does not allocate memory on it's own, there will be no leaks 
due to errors in NumPy.

There is still work to do in the core, i.e. the computational loops in 
array operators, broadcasting, ufuncs, copying data between buffers, etc.

The C functions in the core would then be called with the output array 
already allocated.

Sturla


More information about the NumPy-Discussion mailing list