1

So, what I understand is that in a 64 bit system, a number declared in python takes 64 bits. Is it possible to make it 32 bit, for memory reduction purposes?

MetallicPriest
  • 29,191
  • 52
  • 200
  • 356
  • What kind of number, and using what libraries? E.g. in `numpy` you can get very specific with `dtype`, but e.g. vanilla `int` (`long` in 2.x) are unlimited-precision. – jonrsharpe Nov 10 '14 at 16:25
  • Why do you want to do this? Here's an old SO question about finding the size of variables: http://stackoverflow.com/questions/14372006/variables-memory-size-in-python – Di Zou Nov 10 '14 at 16:27
  • 2
    Python integers are not '32 bit' or '64 bit'. They are Python integers. What problem are you actually trying to solve here? – Martijn Pieters Nov 10 '14 at 16:33
  • Python uses [arbitrary-precision integers](http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic), the bit width of the integer grows when needed to hold large integers. –  Nov 10 '14 at 16:38

1 Answers1

1

If you have a list of numbers that need to be stored, you could use array.array('l') or array.array('L'). You may also use ctypes.c_int(), ctypes.c_uint(), ctypes.c_long(), or ctypes.c_ulong() to store numbers in four bytes.

Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117