[issue18874] Add a new tracemalloc module to trace memory allocations

STINNER Victor report at bugs.python.org
Thu Nov 21 13:24:32 CET 2013


STINNER Victor added the comment:

"Reuse _Py_hashtable for the methods cache is not trivial, the API doesn't fit exactly. I didn't spend much time to try to adapt _Py_hashtable API or the methods cache."

I don't understand which part is the key and which part is the enetry data in method_cache_entry structure:

struct method_cache_entry {
    unsigned int version;
    PyObject *name;             /* reference to exactly a str or None */
    PyObject *value;            /* borrowed */
};

_PyType_Lookup() compares name and version. Does it mean that version is part of the key?

If it's possible to only store name as the key and store version and value in the data, it would be simple to reuse _Py_hashtable. I guess that it would be possible to get a cache entry using the name and later compare the version, it the version doesn't match: don't use the cache. It would require to copy the data (version+value: short structure, a few bytes) from the hash table entry to a local variable (allocated in the stack).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18874>
_______________________________________


More information about the Python-bugs-list mailing list