3 ms·
> I also don’t know where you get “Python float is 24 bytes + 8-byte pointer for each item in the list”. Wat. Not sure how many ways there are to reword that.
by minitech 4y ago
> I also don’t know where you get “Python float is 24 bytes + 8-byte pointer for each item in the list”. Wat.
Not sure how many ways there are to reword that. A CPython float takes 24 bytes of memory, and storing them in a list means 8 bytes per item for the pointer. So in CPython, a list of n floats takes 32n bytes of memory.
>>> sys.getsizeof(1.0)
24
>>> l = list(map(float, range(62_500_000))) # memory use goes up by >2 GB
>>> del l # memory use goes down by >2 GB
(no need to go straight to NumPy to avoid this when relevant, though – array.array is built in.)
- forrestthewoods 4y agoWell I’ll be. 8 bytes for the 64-bit double 8 bytes for object type pointer 8 bytes for reference count Lists are dynamic arrays with object pointers, some another 8 bytes per pointer. TIL and I stand corrected on that point. I thought CPython was more clever than that for lists of floats, but apparently not!