1

I copied the code in this article to implement a dynamic array in python using the ctypes module. Following the author's advice, I began to check the array's size as follows:

import sys
arr = DynamicArray()
for i in range(12):
    arr.append(i)
    a = len(arr)
    b = sys.getsizeof(arr)
    print(a, b)

However, the value for b was 56 each time, the same as the size of the empty array.

Does anyone understand what's happening? Why does the array seem to be storing more elements without taking up any more size in the memory?

Empty Form
  • 11
  • 1
  • Try using `from pympler import asizeof` and then `asizeof.asizeof(arr)` instead. Pympler's [`asizeof.asizeof()`](https://pympler.readthedocs.io/en/stable/library/asizeof.html#pympler.asizeof.asizeof) gives a more complete estimate of object size. – Engineero Sep 26 '18 at 17:26
  • Thanks, unfortunately I ran into the same problem with `asizeof.asizeof(arr)`, where it just returned the same value no matter how many items were stored in `arr`. – Empty Form Sep 27 '18 at 22:29

0 Answers0