[Python-ideas] namedtuple from ordereddict

Jim J. Jewett jimjjewett at gmail.com
Thu Jul 20 16:17:05 EDT 2017


Several of the replies seemed to suggest that re-using the current
dict structure for a tuple wouldn't work.  Since I'm not sure whether
people are still thinking of the old structure, or I'm missing
something obvious, I'll be more explicit.

Per https://github.com/python/cpython/blob/master/Include/dictobject.h#L40
the last element of a dict object is now a separate pointer to
ma_values, which is an array of objects.

Per https://github.com/python/cpython/blob/master/Include/tupleobject.h#L27
the last element of a tuple object is also an array of objects.

Is there some reason these arrays cannot be the same memory?  e.g.,
does a tuple header *have* to be contiguous with its data, and if so,
is there a reason that the dict's ma_array can't be allocated with an
extra tuple-header prefix?

-jJ


More information about the Python-ideas mailing list