[pypy-dev] Arrays in rpython

Amaury Forgeot d'Arc amauryfa at gmail.com
Mon Jun 6 20:52:40 CEST 2011


Hi,

2011/6/6 Timothy Baldridge <tbaldridge at gmail.com>:
> Is there a way in rpython to specify that a given list should be
> implemented as an array? I want to create a list of objects exactly 32
> entries long. I could use [] but it seems like that would be slower
> than using an array. In CPython I can create an array of primitive
> types, but I'm looking to create a array of object types.

In case you don't already know: in Python (and RPython), lists are
implemented as
resizeable arrays, i.e. they look more like a C++ std::vector and not
a std::list.

This said, IIRC RPython has special code for fixed-size lists.
I think you just have to avoid all resizing functions.
This means that the list must be created with statements like
    array_of_ints = [0] * 32
    array_of_objects = [None] * 32

-- 
Amaury Forgeot d'Arc


More information about the pypy-dev mailing list