Lists, tuples and memory.

Peter Otten __peter__ at web.de
Sat Jul 17 01:41:04 EDT 2004


Terry Reedy wrote:

> "Peter Otten" <__peter__ at web.de> wrote in message
> news:cd936h$akf$06$1 at news.t-online.com...
>> Christopher T King wrote:
>>
>> > Try using a set instead of a dictionary. You should get the good access
>> > time of dictionaries with nearly the low memory usage of a list:
>>
>> sets.Set() holds its data in a dict. I fear the same goes for 2.4's
> builtin
>> set type which is coded in C but also built on top of dict.
> 
> My impression was that it was based on the dict code, but without reading
> the source, I don't really know.

The "fear" was rhetoric, I actually looked it up. In setobject.c, as of
2.4a1:

make_new_set(PyTypeObject *type, PyObject *iterable)
{
        PyObject *data = NULL;
        PyObject *tmp;
        PySetObject *so = NULL;

        data = PyDict_New();
        if (data == NULL)
                return NULL;
        ....

Peter





More information about the Python-list mailing list