[issue21419] Use calloc() instead of malloc() for int << int (lshift)

STINNER Victor report at bugs.python.org
Fri May 2 23:02:53 CEST 2014


STINNER Victor added the comment:

Without the patch, 1 << (2**29) allocates 69.9 MB. With the patch, 1 << (2**29) allocates 0.1 MB (104 KB).

Without the patch, 

$ ./python
Python 3.5.0a0 (default:5b0fda8f5718, May  2 2014, 22:47:06) 
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux
>>> import os
>>> os.system("grep RSS /proc/%s/status" % os.getpid())
VmRSS:	    6164 kB
>>> x=1 << (2**29)
>>> os.system("grep RSS /proc/%s/status" % os.getpid())
VmRSS:	   76064 kB

With the patch:

haypo at selma$ ./python
Python 3.5.0a0 (default:5b0fda8f5718+, May  2 2014, 22:55:47) 
[GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system("grep RSS /proc/%s/status" % os.getpid())
VmRSS:	    5864 kB
>>> x=1 << (2**29)
>>> os.system("grep RSS /proc/%s/status" % os.getpid())
VmRSS:	    5968 kB

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21419>
_______________________________________


More information about the Python-bugs-list mailing list