On Thu, Jan 14 2021, Pablo Galindo Salgado wrote:

Hi Pablo,

> Isn't this a similar problem that you have with regular malloc? When you
> call malloc() with
> some size, malloc actually will reserve more than that for
> alignment purposes and for
> bookkeeping and apart from some platform-specific APIs
> like malloc_usable_size()
> you cannot query that value.

Not really. It's not a real problem if malloc reserve more memory than
the size you requested if you still know the original size.
When working with Python memory allocator API, you do have this original
size so you're able to read the memory from its beginning (the allocated
pointer address) to its end.

> My answer would be that that's because memory itself cannot be gc tracked,
> only objects can and those belonging to different
> categories. For example, notice that the tracemalloc module does not report
> objects, it only reports memory blocks and you
> cannot ask tracemalloc to give you a list of all the objects that were
> allocated because it does not have the notion of what
> an object is.

Exactly, which is a bit a bummer. Considering Python provides 3
different memory allocator, it'd be great if there was some ability to
be sure that PyObject_Malloc pointer are actually PyObject, not
Py_GC_HEAD.

-- 
Julien Danjou
// Free Software hacker
// https://julien.danjou.info
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/MMCIEUV62ER6DWYG7FVIRCRD2KI3E4EZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to