5 ms·
The default malloc and free, depending on platform, can be ridiculously slow operations (on the range of 50-100µs). Those numbers are old, they are from some te
by mrcharles 16y ago
The default malloc and free, depending on platform, can be ridiculously slow operations (on the range of 50-100µs). Those numbers are old, they are from some testing I did nearly a decade ago. I'd hope it would have improved right now.
But at that time, I wrote a memory manager which had malloc and free calls which were a magnitude faster, at least ten times.
When you need it to be fast, it can be fast. If you don't want it to be fast, or you have to resort to tricks like preventing the compiler from inlining (wtf?), then you really are doing it wrong.
- ekidd 16y agoReally? One allocation every 50 to 100ms? That would mean you could only do 10 to 20 memory allocations per second. Now, I know that malloc is often very slow, but that seems unlikely. Or do you mean 50 to 100 microseconds? That's still horrible, but I could believe it.
- npalli 16y ago50-100ms is just horrible. In fact, the best malloc's show operations in 50-100 nanoseconds. http://goog-perftools.sourceforge.net/doc/tcmalloc.html http://goog-perftools.sourceforge.net/doc/tcmalloc.html
- jedbrown 16y agoYes, even glibc malloc is usually around 400 cycles (about 150 nanoseconds) in my tests.
- JoeAltmaier 16y agoWindows "garbage collects" in its memory manager anyway; so no actually benefit using C++ etc there. It uses some pool with fragmentation algorithms that can take 100s of milliseconds to complete.