|
|
|
|
|
by OptionOfT
109 days ago
|
|
> ...
> On the third loop iteration, the backing store of size 2 is full. append again has to allocate a new backing store, this time of size 4. The old backing store of size 2 is now garbage. Correct me if I'm wrong, but isn't this a worst-case scenario? realloc can, iirc, extend in place. Your original pointer is still invalid then, but no copy is needed then. Unless I'm missing something? Equally, what happens to the ordering of variables on the stack? Is this new one pushed as the last one? Or is there space kept open? E.g.: var tasks []task
var other_var int
|
|