in reply to Re^4: How to implement a Queue that doesn't leak memory?
in thread How to implement a Queue that doesn't leak memory?

It would be interesting to know how and when this reallocation happens and if it's automatically done on C-level.

No, nothing is automatic in C. Heck, C barely has arrays but normally you would malloc(3) an intial size and when you need more memory you would use realloc(3) to ask for more. A lot of time realloc can just extend the array but sometimes it needs to allocate more space and memcpy into the new larger space.

I wish I had the link where I saw it (LWN?) but it turns out that, in practice, Linux can do some magic with pages and you almost never get that stall from having to copy the whole array.

I don't know what perl does under the covers but it is extremely likely it follows this traditional approach.

  • Comment on Re^5: How to implement a Queue that doesn't leak memory?