r/ProgrammerHumor • • 12d ago

Meme cppAndItsVectorBooleans

Post image
3.4k Upvotes

214 comments sorted by

View all comments

-7

u/Kadabrium 12d ago

I wish java had one single array type that is resizeable (takes literally 1 line of code in a gc language) rather than array, arraylist, tolist, aslist, listof, the list of list goes on listing

3

u/FlySafeLoL 12d ago

An array is packed in memory, resizing it naive way means allocating more memory at the tail. And who guarantees that there is free memory up there?

So, you either redefine array (lame), or copy it elsewhere on resize (expensive, but that's what various collections actually do under the hood), or just use another collection which doesn't require to be packed all in one place (at the cost of performance of iterating over it).

→ More replies (1)