As I am new to python could any one tell me what is the maximum memory size that a list in python can accommodate. a = [1,2,3,45] For instance let size of 'a' be 10 bytes. So I would like to know how many such bytes can be the maximum limit for the list. Does it in anyway depend on RAM?
Asked
Active
Viewed 2,731 times
1
-
2I'm not sure, but I think `print sys.maxsize` gives an indication. – Maroun Mar 31 '15 at 07:20
-
There is also [getsizeof](https://docs.python.org/3/library/sys.html#sys.getsizeof) that can be useful to check memory usage. – Marcin Mar 31 '15 at 07:26
-
possible duplicate of [Python memory limit](http://stackoverflow.com/questions/21102429/python-memory-limit) – JuniorCompressor Mar 31 '15 at 07:27
-
1@MarounMaroun, you are right, see [repo](https://hg.python.org/releasing/2.7.9/file/753a8f457ddc/Objects/listobject.c#l51). Perhaps you'd like to make it an actual answer. It's not like the memory is the limit, it's the counter causing overflow that can also trigger `MemoryError`. – Maciej Gol Mar 31 '15 at 07:28
-
I have 16gb RAM, and doing `>>> a = [0]*2000000000` occupies 14.9gb. Refer here for the limits - http://stackoverflow.com/questions/855191/how-big-can-a-python-array-get – hyades Mar 31 '15 at 07:51
-
Don't confuse RAM with virtual memory! Very few programs write explicitly to RAM, certainly Python does not. RAM size is not irrelevant but is more likely to affect performance (paging) than limits. How Python handles memory depends on the operating system and on the Python version. – cdarke Mar 31 '15 at 08:15