内存分配/释放瓶颈? [英] Memory Allocation/Deallocation Bottleneck?

查看:106
本文介绍了内存分配/释放瓶颈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在典型的真实世界的程序中,内存分配/释放有多大瓶颈?来自任何性能通常很重要的程序的答案都是受欢迎的。 malloc / free / garbage collection的体面实现是否足够快,以至于它只是一些特定情况下的瓶颈,或者大多数性能关键型软件会从试图保持内存分配量减少或拥有更快的malloc / free /垃圾回收实现?



注意:我不是在这里讨论实时的东西。对性能至关重要,我的意思是吞吐量很重要,但延迟并不一定。



编辑:虽然我提到malloc,但这个问题是 not <这是非常重要的,特别是在碎片增长和分配器不得不跨越更难的情况下寻找对于您要求的连续区域,堆积较大。大多数对性能敏感的应用程序通常都会编写自己的固定大小的块分配器(例如,他们一次向操作系统请求16MB内存,然后以4kb,16kb等固定块对其进行打包处理),以避免此问题。



在游戏中,我看到malloc()/ free()的调用消耗了多达15%的CPU(在写得不好的产品中),或者仔细写入和优化的块分配器,只有5%。鉴于游戏必须具有60赫兹的一致吞吐量,因此在垃圾收集器偶尔运行的情况下拖延500毫秒是不现实的。

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. Are decent implementations of malloc/free/garbage collection fast enough that it's only a bottleneck in a few corner cases, or would most performance-critical software benefit significantly from trying to keep the amount of memory allocations down or having a faster malloc/free/garbage collection implementation?

Note: I'm not talking about real-time stuff here. By performance-critical, I mean stuff where throughput matters, but latency doesn't necessarily.

Edit: Although I mention malloc, this question is not intended to be C/C++ specific.

解决方案

It's significant, especially as fragmentation grows and the allocator has to hunt harder across larger heaps for the contiguous regions you request. Most performance-sensitive applications typically write their own fixed-size block allocators (eg, they ask the OS for memory 16MB at a time and then parcel it out in fixed blocks of 4kb, 16kb, etc) to avoid this issue.

In games I've seen calls to malloc()/free() consume as much as 15% of the CPU (in poorly written products), or with carefully written and optimized block allocators, as little as 5%. Given that a game has to have a consistent throughput of sixty hertz, having it stall for 500ms while a garbage collector runs occasionally isn't practical.

这篇关于内存分配/释放瓶颈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆