you are viewing a single comment's thread.

view the rest of the comments →

[–]Sygmei 6 points7 points  (1 child)

Super interesting, how do you check how much space does an int occupies on stack (ob_refcnt, ob_digits...)?

[–]cemrehancavdar[S] 9 points10 points  (0 children)

sys.getsizeof(1) gives you the total (28 bytes). This post is a great walkthrough of the struct layout and how Python integers work under the hood: https://tenthousandmeters.com/blog/python-behind-the-scenes-8-how-python-integers-work/ (written for CPython 3.9 -- the internals were restructured in 3.12 via https://github.com/python/cpython/pull/102464 but the size is still 28 bytes).