What are the currently possible values for sys.maxsize?

1.5k Views Asked by At

In the latest Python 2 documentation:

sys.maxsize

The largest positive integer supported by the platform’s Py_ssize_t type, and thus the maximum size lists, strings, dicts, and many other containers can have.

In the latest Python 3 documentation:

sys.maxsize

An integer giving the maximum value a variable of type Py_ssize_t can take. It’s usually 2**31 - 1 on a 32-bit platform and 2**63 - 1 on a 64-bit platform.

The value sys.maxsize is in this file used on Python 2 with the values specified in the Python 3 documentation:

  • 2**31 - 1 = 2147483647;
  • 2**63 - 1 = 9223372036854775807.

My question is: what are the possible values sys.maxsize can take in Python 2? Are these two part of the possible values or not? Are there any other possible values (on other platforms or operating systems, for example)? It would be interesting to find the possible values that it can take in Python 3 too.

Related questions:

2

There are 2 best solutions below

1
On BEST ANSWER
  • sys.maxsize is telling you something about the C compiler used to compile CPython, so there's no difference between Python 2 and Python 3. It has to do with the C compiler and options that were used, not with the version of Python being compiled.
  • It's the largest positive integer that fits in the platform C compiler's ssize_t type. Which is a 32-bit or 64-bit signed 2's-complement integer on all platforms I've ever seen ;-) Which correspond exactly to the two specific values you already found.
  • It's called type Py_ssize_t in the docs because Python had to create its own typedefs (at the C level) for newer C concepts waiting for all the world's C compilers to implement them. Those Python-specific typedefs typically stick around in the source code even after all known C compilers catch up ("not broke, don't fix").
0
On

Two possible values are due to the python bit version.

+=============+=====================================+======================================+
|             |            Python 32 bit            |            Python 64 bit             |
+=============+=====================================+======================================+
| sys.version | 3.7.3 ….[MSC v.1916 32 bit (Intel)] | 3.7.4 …..[MSC v.1916 64 bit (AMD64)] |
+-------------+-------------------------------------+--------------------------------------+
| sys.maxsize | 2147483647                          | 9223372036854770000                  |
+-------------+-------------------------------------+--------------------------------------+