Memory Allocation/Deallocation Bottleneck?

后端 未结 12 1988
轮回少年
轮回少年 2020-11-30 20:44

How much of a bottleneck is memory allocation/deallocation in typical real-world programs? Answers from any type of program where performance typically matters are welcome.

12条回答
  •  一个人的身影
    2020-11-30 21:24

    Nearly every high performance application now has to use threads to exploit parallel computation. This is where the real memory allocation speed killer comes in when writing C/C++ applications.

    In a C or C++ application, malloc/new must take a lock on the global heap for every operation. Even without contention locks are far from free and should be avoided as much as possible.

    Java and C# are better at this because threading was designed in from the start and the memory allocators work from per-thread pools. This can be done in C/C++ as well, but it isn't automatic.

提交回复
热议问题