Python object overhead?

7stud bbxx789_05ss at yahoo.com
Sat Mar 24 16:52:46 EDT 2007


On Mar 24, 2:19 pm, Jean-Paul Calderone <exar... at divmod.com> wrote:
> Only one list is created.  It is used to define a C array where attributes
> will be stored.  Each instance still has that C array, but it has much less
> overhead than a Python list or dictionary.
>

It's all C underneath, right?  So a dictionary is what?  Two parallel
C arrays: one array with the names and one with the values?

When you do this:

__slots__ = ["m", "n"]

there still has to be a mapping between the names "m" and "n" and
their values.  So aren't two parallel C arrays required again?

> Whether this reduction in overhead actually results in a useful or measurable
> performance improvement is a separate question, of course.
>

I suppose a dictionary will be required to grow in size, so at
periodic intervals new, bigger arrays will need to be created, the
contents copied over, and the old arrays destroyed(similar to a
<vector> in C++).  And of course, the C code that accomplishes all
that creating, copying and destroying will take up some memory.

Is that what you are talking about when you say "overhead"?






More information about the Python-list mailing list