![]() ![]() The list taking that much memory isn’t surprising–a Python list is essentially an array of pointers to arbitrary Python objects. Side note: You would get the same memory usage if you did list(range(1000000)), but I structured the code this way to make it clearer where each chunk of memory usage came form. If we profile the code snippet above, here’s the allocations used:Īs you can see if you hover or click on the frames: Let’s see what’s going on under the hood, and then how using NumPy can get rid of this overhead. In fact, Python uses more like 35MB of RAM to store these numbers.īecause Python integers are objects, and objects have a lot of memory overhead. Those numbers can easily fit in a 64-bit integer, so one would hope Python would store those million integers in no more than ~8MB: a million 8-byte objects. List_of_numbers = for i in range ( 1000000 ): list_of_numbers.
0 Comments
Leave a Reply. |