Here's an example of what (in this magical language that might not exist) I'd like to do. Lastly, even if this is possible in theory, would it be inefficient and inferior to something like Rust, well-written heap-enabled C++, etc.? we have a lightweight Task concept that uses a doubly-linked list for task management all managed on the stack and using returns) - but could a compiler theoretically track objects still in play (again, only using stack and static analysis no GC or reference counting allowed) and return all those objects in the background, rearranging the stack as necessary? Obviously this can be explicitly via return - and in some cases we do that (e.g. C stack vs heap: The Stack is a linear memory allocation structure that is used for the temporary storage of data with a short lifespan such as function call parameters and local variables. This article focuses on two kinds of memories: stack and heap. In fact, every time you create a new variable, your program is allocating more memory for you to store that variable. Sometimes we are not even aware of the memory being allocated. However, in a perfect world we would also be able to create certain resources on the stack and have them returned to the previous scope. Overview When a program is running, it takes up memory. On our team we use the stack as a large object graph and essentially inject dependencies all the way down. In order to write efficient and optimized code, it is essential to comprehend the difference between Stack and Heap memory. Is it possible in theory to have a programming language that allows for object lifetimes that exist beyond the current scope but without using heap?Īs a little background, in embedded development it can often be advantageous to avoid heap and lean heavily on the stack. The main difference between the two is that Stack memory is allocated and deallocated in a predictable and deterministic manner, while Heap memory is allocated dynamically and can lead to fragmentation over time.
0 Comments
Leave a Reply. |