[Python] In the context of Key-Sharing Dictionaries, what does sys.getsizeof measure?

Discussão em 'Python' iniciado por Stack, Junho 17, 2025.

  1. Stack

    Stack Membro Participativo

    If I understand correctly, Key-Sharing dictionaries make it so that if we have loads of instances of an object, we have a Shared Keys Table, and each instance then has a Value Array. What does sys.getsizeof measure, e.g.:

    import sys

    class Property:
    def __init__(self, v0, v1, v2, v3, v4):
    self.a = v0
    self.b = v1
    self.c = v2
    self.d = v3
    self.e = v4

    colors = Property('blue', 'orange', 'green', 'yellow', 'red')

    sys.getsizeof(vars(colors)) # 296 (Python 3.12.5)


    What does this 296 refer to, does it refer to shared keys table + value array of the instance, or just the value array of the instance?

    Also, why is it that this array is much bigger in Python 3.12.5 compared to Python 3.10.11 (104 in Python 3.10.11, 296 in Python 3.12.5)? Did the way sys.getsizeof() work change in between those two versions or did the implementation of dictionaries change in between those two versions?

    Continue reading...

Compartilhe esta Página