3 ms·
> the efficiency gains of new/delete over malloc/free are going to become apparent. I think that you overlook how the model of new/delete encourages thinking a
by mariusor 5y ago
> the efficiency gains of new/delete over malloc/free are going to become apparent.
I think that you overlook how the model of new/delete encourages thinking about memory in individual chunks (of the size of your class) instead of a small number of large chunks that can be split into individual pieces as needed, but make the overhead of allocating/deallocating memory much, much lower.
- zozbot234 5y agoC++ has placement new and custom allocators for this. Rust actually has a harder time doing these things, though local allocators are in the works for Rust too.
- mariusor 5y agoMy C++ is very rusty (pun not intended), I had no idea you can plug in a custom allocator but still use new/delete for initialization. Do you maybe have a link to something where I can read more about this?
- tialaramex 5y agoThe C++ new keyword is just an operator and so you can overload it like most C++ operators, to do whatever you want. In fact it's not just one operator, it's a whole family of them.
- jeffbee 5y agoIn my opinion arena allocation is much more idiomatic, and more commonly seen, in C++ than it is in C.