第一个问题是,你真的需要新吗?所有小的对象? First question is, do you really need to "new" all thost small objects ? ....如果是,请尽量减少使用new的分配数量。我知道 STL中的容器通过预先分配比 所需的更多内存来做到这一点,以防止内存碎片化并最大限度地减少 $ b的数量$ b分配(以及他们所需的时间)。 Catalin.... and if yes, try to minimize the number of allocations with new. I knowthat the containers in STL do this by allocating in advance more memory thanneeded, to prevent memory fragmentation and to minimize the number ofallocations (and the time needed for them).Catalin 索取一份 有效的C ++ Scott Meyers 第10项(如果你编写新的运算符,则写入运算符删除) 讨论了一个解决方案。 < Quote> 让我们退一步,回到基本面。为什么有人想首先编写他们的 自己版本的operator new或operator delete? 通常,答案就是效率。 operator new和 operator delete的默认版本完全适合一般用途,但它们的灵活性 不可避免地为在更受限制的 上下文。对于动态分配大量小型物品的应用程序尤其如此。 .... < /引用> - Karl Heinz Buchegger kb ****** @ gascad.at 这篇关于任何加速“新”的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 04:33