Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Audio and Game devs: Need to port my custom malloc and ring buffer code to get rid of those malloc pauses

JavaScript devs: Foolish audiophiles think they can hear when someone calls malloc!

Mis-diagnosing a problem doesn't mean there isn't a problem. If you call memcp in a way that calls malloc, and your app has been running a while or your system doesn't have a lot of free memory, you're going to get pauses while malloc looks for a free address block. If that pause takes too long, your audio buffer will stall and cause a harsh crackle. People will hear that differently, and explain the problem in different ways.

TL;DR: audio and game programming sucks, and if you allocate heap memory people will actually notice.

In the extreme:

  Imagine my surprise when the customers chief software engineer said "Of course it leaks".  He went on to point out that they had calculated the amount of memory the application would leak in the total possible flight time for the missile and then doubled that number.  They added this much additional memory to the hardware to "support" the leaks.
https://web.archive.org/web/20170504104857/https://groups.go...


> If you call memcpy in a way that calls malloc

uh... How exactly?

memcpy copies memory from one place in memory to another. That's all it does. There is no "calling memcpy in a way that calls malloc".


if dst and src in memcpy overlap, the result is UB. so there's your window of opportunity.

well, you asked...


Haha, you're right, it's technically allowed for memcpy to call malloc in that circumstance.


memcpy wouldn't, but memmove would. memcpy doesn't check for or care about overlaps (and therefore the result is unpredictable - it'll depend on the implementation)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: