size of references to objects #16282
Replies: 1 comment 1 reply
-
All references fit in a single small int. Pre-allocating does not make assignment allocation-free. Consider this case a = list(None for _ in range(5))
d = {1: "one", 2 : "two"}
a[0] = d The outcome of line 1 is a 5-list where every element is a reference to the The alternative a = []
d = {1: "one", 2 : "two"}
a.append(d) must do additional allocation to create the list element. However, as far as I can see, the only difference with the first case is that this list element allocation occurs later. As a general point there is no need to worry unduly about allocation unless creating large buffers, writing hard interrupt service routines or optimising a key code section for performance. |
Beta Was this translation helpful? Give feedback.
-
In 'the docs", recommendations are included to limit memory fragmentation. Is there a (best) way to upfront reserve space for variables stored in a list or dict where those entries will later be filled with references to object instances. Does the reference to instance a1, a2, a3... ax of class A have a predetermined format/size that I can (should?) allocate upfront ?
thx !
Beta Was this translation helpful? Give feedback.
All reactions