3 ms·
> So... Because lists are dynamically typed and heterogeneous, does that mean the underlying C is basically a contiguous segment of memory of python object refe
by haikuginger 8y ago
> So... Because lists are dynamically typed and heterogeneous, does that mean the underlying C is basically a contiguous segment of memory of python object references?
Yes. Every Python object is held by the interpreter as a pointer to a PyObject struct on the (C) heap.
- aggerdom 8y agoNot something I would put into production, but had a fun application of this on a side project. I had the `id` of a function (but not the function object itself) and needed to recover the function. In CPython, `id` of a function corresponds to it's memory address (not sure if that can be overridden). By casting the id to a PyObject, I was able to recover the original. func = ctypes.cast(int(address), ctypes.py_object).value Was kinda cool actually seeing that work.