Title: Allocating extra data after an object instance · Issue #103743 · python/cpython · GitHub
Open Graph Title: Allocating extra data after an object instance · Issue #103743 · python/cpython
X Title: Allocating extra data after an object instance · Issue #103743 · python/cpython
Description: Feature or enhancement Add an unstable (in PEP 689 sense) function that allocates memory for a GC object and allows the caller to specify the size of additional memory that should be allocated after the object. Similar to what could be d...
Open Graph Description: Feature or enhancement Add an unstable (in PEP 689 sense) function that allocates memory for a GC object and allows the caller to specify the size of additional memory that should be allocated afte...
X Description: Feature or enhancement Add an unstable (in PEP 689 sense) function that allocates memory for a GC object and allows the caller to specify the size of additional memory that should be allocated afte...
Opengraph URL: https://github.com/python/cpython/issues/103743
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allocating extra data after an object instance","articleBody":"# Feature or enhancement\r\n\r\nAdd an unstable (in PEP 689 sense) function that allocates memory for a GC object and allows the caller to specify the size of additional memory that should be allocated after the object. Similar to what could be done using `_PyObject_GC_Malloc` function in Python \u003c= 3.10.\r\n\r\n# Pitch\r\n\r\nCurrently there is no way of allocating extra data after an object and still being able to have a standard Python class that supports GC, allows inheriting and doesn't come with limitations of `PyVarObject` (see #103740).\r\n\r\nSee the linked discussion for more details, but in essence the use case is the following. We have a base class and metaclass that support defining \"slots\" on classes (similar to Python `__slots__`, but with a different behavior, more on that later). The data for the slots is stored after the object, in the same block of memory. When inheriting from a class that defines such \"slots\", the subclass gets all the slots from its base classes + slots defined on it. The data for all those slots is always stored after the object, so the slot storage size doesn't really come into calculation for `tp_basicsize`.\r\n\r\nA nice effect of this behavior is that a subclass can inherit from multiple classes with each of the bases defining its own slots. The subclass then gets all those slots, as if they were directly defined on it (in contrast with Python `__slots__`, which prevents such inheritance).\r\n\r\nCC: @encukou \r\n\r\n# Previous discussion\r\n\r\nSee [this discussion](https://discuss.python.org/t/equivalent-of-pyobject-gc-malloc-in-python-3-11/25919) for more details.\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-103744\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/jbradaric","@type":"Person","name":"jbradaric"},"datePublished":"2023-04-24T08:03:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/103743/cpython/issues/103743"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2c24a840-d7a9-55f1-37a2-1a853ebcbf62 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 977E:26204A:11BB26E:17C9740:6969AA07 |
| html-safe-nonce | 8318b7d8e0cafa23a74f0b2a69f7fa6aa9fc1f9ab55697541bf3fb8e186bc707 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzdFOjI2MjA0QToxMUJCMjZFOjE3Qzk3NDA6Njk2OUFBMDciLCJ2aXNpdG9yX2lkIjoiNDU3ODM2ODI4MjU4MDUyNjE1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1352233490c8cebd910045682ee7cbfca3b7f8b4adfc5b22318b80c6bf9059de |
| hovercard-subject-tag | issue:1680680326 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/103743/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b222c4819e0c2f1ce1cf7c0a20627fcc6729d4b594de3279c5bdce5a052f61b0/python/cpython/issues/103743 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b222c4819e0c2f1ce1cf7c0a20627fcc6729d4b594de3279c5bdce5a052f61b0/python/cpython/issues/103743 |
| og:image:alt | Feature or enhancement Add an unstable (in PEP 689 sense) function that allocates memory for a GC object and allows the caller to specify the size of additional memory that should be allocated afte... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jbradaric |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width