Swapping values of two variables

Christian Heimes lists at cheimes.de
Fri Jan 30 10:49:15 EST 2009


Steven D'Aprano schrieb:
> Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes 
> (96 bits) in size; a long will use as much memory as needed. If your 
> application needs to optimize a swap of two ints, then Python is probably 
> going to be much too memory-intensive for you.

An int object consumes more than 12 bytes of memory. It depends on the
system architecture, too. It's usually 16 bytes on a 32bit system and 24
bytes on a 64bit system.
The actual size can be computed by sizeof(ptr) + sizeof(long) +
sizeof(ssize_t). The size is rounded up to the next multiple of 8 bytes
due to address alignment.

Christian




More information about the Python-list mailing list