2013/3/7 Zaur Shibzukhov <szp...@gmail.com>

> I guess the problem is to construct new (even empty) list with
> pre-allocated memory exactly for N elements.
>
> N*[NULL] - changes semantics because there can't be list with N elements
> and filled by NULL.
> N*[None] - more expansive for further assignments because of Py_DECREFs.
>
> I suppose that N*[] could do the trick. It could be optimized so that N*[]
> is equal to an empty list but with preallocated memory exactly for N
> elements. Could it be?
>
>
Cython optimize already PyList_Append very well. Theofore scenario when
first one create empty list with exactly prealocated memory for N elements
 and second eval elements of the list and add them using plain list.append
could optimized in Cython very well too. As result constructed list will
contain memory only for N elements. This allows don't vast memory when one
need to build many many lists with relative big size.

Zaur Shibzukhov
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to