Python List Memory Storage

Viewed 18803

I understand that Python lists are essentially C arrays, that they allocate a specific block of sequential memory; but, do these pieces of memory actually store the data that is in the list or do they simply point to another location in memory where the actual data is stored?

Does it perhaps depend on the size of the object stored in the list? As you could easily store a list of ints sequentially but it would be harder to dynamically store a variety of objects including self-defined objects.

2 Answers

No, python lists store references ("pointers") to the objects

Performance Notes #

The list object consists of two internal parts; one object header, and one separately allocated array of object references. The latter is reallocated as necessary.

Related