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?

2
  • Try using from pympler import asizeof and then asizeof.asizeof(arr) instead. Pympler's asizeof.asizeof() gives a more complete estimate of object size. Commented Sep 26, 2018 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. Commented Sep 27, 2018 at 22:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.