I have a project that I am planning, and one bit of information I'll want to have is how much memory a reference takes up in Python. AFAIK, a reference in python is the same as a pointer, and I am guessing that it would be the same size as a 32bit or 64bit pointer (but I could be wrong).
Could anyone clear this up for me, so that I don't have to go on guesswork?
The Python __sizeof__() method returns the size of the object in bytes. The sys. getsizeof() method internally call's __sizeof__() and adds some additional byte overhead, e.g., for garbage collection.
In python, the usage of sys. getsizeof() can be done to find the storage size of a particular object that occupies some space in the memory. This function returns the size of the object in bytes.
why reference size is always 4 bytes - c++
@SuperBiasedMan Good point, thanks. Looks like it's 8 bytes, which is the size you'd expect of a pointer in a 64bit program.
This was answered in the comments through a discussion between me and SuperBiasedMan. The size of a reference in Python is the same as the word size for the CPU. So, it's 4 bytes on a 32bit build of python, and 8 bytes on 64bit python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With