4 ms·
Some people who use C don't want a destructor like feature for performance reasons. They would prefer everything is cleaned up in some global context rather tha
by flumpcakes 5y ago
Some people who use C don't want a destructor like feature for performance reasons. They would prefer everything is cleaned up in some global context rather than each object in a chain of stack frames having to clean themselves up when an error somewhere buried deep in code.
I don't have any benchmarks because I don't work on low level code all day, but apparently it can be slow enough that it puts people off using destructors. This isn't a joke.
In fact, some people will not use new/delete. Some people will also go further and not even use malloc but prefer to use the syscalls for getting a block of memory directly from the operating system and managing it completely themselves. These are usually the people who don't use the standard library/libc.
- ncmncm 5y agoI do all that in C++: substantial allocations, like ring buffers, are mmapped with a MAP_HUGETLB flag or on /dev/hugepages. And, I use a destructor to unmap them. Suggesting destructors slow down execution really is a joke. The joke is on people who believe it. People will grasp at any straw to avoid need to learn anything new.