Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Size of Reference?

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?

like image 477
Zauber Paracelsus Avatar asked May 19 '15 15:05

Zauber Paracelsus


People also ask

What is __ sizeof __ in Python?

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.

How do I check the size of a Python?

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.

What is the size of a reference to an int variable?

why reference size is always 4 bytes - c++

How many bytes is a pointer in Python?

@SuperBiasedMan Good point, thanks. Looks like it's 8 bytes, which is the size you'd expect of a pointer in a 64bit program.


1 Answers

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.

like image 66
Zauber Paracelsus Avatar answered Oct 05 '22 14:10

Zauber Paracelsus