[Cython] Cython syntax to pre-allocate lists for performance

Yury V. Zaytsev yury at shurup.com
Thu Mar 7 12:16:10 CET 2013


Is there any syntax that I can use to do something like this in Cython:

    py_object_ = PyList_New(123); ?

If not, do you think that this can be added in one way or another?

Unfortunately, I can't think of a non-disruptive way of doing it. For
instance, if this

    [None] * N

is given a completely new meaning, like make an empty list (of NULLs),
instead of making a real list of Nones, it will certainly break Python
code. Besides, it would probably be still faster than no pre-allocation,
but slower than an empty list with pre-allocation...


    [NULL] * N ?

Any ideas?

Sincerely yours,
Yury V. Zaytsev

More information about the cython-devel mailing list