On the use and abuse of alloca

后端 未结 5 1241
温柔的废话
温柔的废话 2020-12-15 04:33

I am working on a soft-realtime event processing system. I would like to minimise as many calls in my code that have non-deterministic timing. I need to construct a message

5条回答
  •  别那么骄傲
    2020-12-15 05:08

    Well first of all, even though there is a lot of virtual memory doesn't mean your process will be allowed to fill it. On *nix there are stack size limits, whereas the heap is a lot more forgiving.

    If you're only going to be allocating a few hundred / thousand bytes, sure go ahead. Anything beyond that is going to depend on what limits (ulimit) are in place on any given system, and that's just a recipe for disaster.

    Why is the use of alloca() not considered good practice?

    On my development box at work (Gentoo) I have a default stack size limit of 8192 kb. That's not very big, and if alloca overflows the stack then the behavior is undefined.

提交回复
热议问题