3 ms·
That kind of defeats the purpose. Heap allocation is meant for objects that persist for the long-term. Stack allocation is meant for short-term storage, and any
by rcfox 15y ago
That kind of defeats the purpose. Heap allocation is meant for objects that persist for the long-term. Stack allocation is meant for short-term storage, and anything that is allocated on the stack is lost when the function returns.
- apaprocki 15y agoYou can always allocate stack space (static or dynamic with alloca()) in main() before kicking off the application.
- ajross 15y agoIn which case it's isomorphic to a static memory block (albeit one with non-zero initialization costs), so what would the point be?
- icefox 15y agoWell the whole article seemed silly after he said this: "First of all, you can't use heap - not when you're in orbit. Why? Because quite simply, if you do use heap, and malloc returns null... what do you do? You can't ask the user for help" This is the OOM problem and is highly dependent upon the kernel you are using. Not bringing the kernel into the discussion means that the discussion is just silly. There is not much of a point to putting the heap in the stack as you said, but hey like the author we are just getting some ideas out there without bringing up the kernel.
- ttsiodras 15y agoI think you misinterpreted the article: the target is not Linux/x86, its a custom board with the SPARC/Leon processor running a custom embedded OS (RTEMS), launched in space :-) The article is just an example of the notions used, and how objdump can be used to enforce them. Linux is used simply for demonstration purposes. In your average PC with Linux/x86, it is clear that you fear neither stack nor heap error - you just restart the app :-)
- icefox 15y agoI think you misinterpreted my comment. I didn't mention Linux anywhere in it, but specifically talk about how when dealing with OOM you must first discuss what the kernel provides. On RTEMS can malloc actually return 0 or does it never return 0 and there is a signal or some other event that is sent out from the kernel? These are the most important bits of information in this problem.