Is it possible to model memory on the stack / heap?

I can't figure out if using the stack / heap memory model is a programmer's decision or is OS specific and the programmer has no choice but to work with it.

For example, can stack languages ​​like Fortran77 work on modern platforms using a no-stack array-based memory model? Or should modern Fortran compilers translate the array memory model into a stack / heap memory model instead? (I can't find much documentation on Fortran memory management.)

If the memory model is the solution for the programmer, why is everything I run into implicitly assuming the stack / heap model is the only option? For example LLVM deals with stack frames and I can't find any documentation on memory management in any other way. All languages ​​built on LLVM, even functional languages, should then use the stack / heap model when alternative models may be more appropriate.

If the memory model is a solution for the OS, does that mean that writing a program that uses a custom memory model requires a custom OS entry? For example, do I need a special OS if I want to run a Fortran program that uses an array based memory model? Fortran was designed around?

If the answer is OS dependent, please give a few comparisons across OSes.

+3


source to share


2 answers


The stack and the heap have nothing to do with Fortran, the standard says nothing about them. Likewise C, at least until C89, after that my knowledge becomes less good. Rather, the compiler must translate the language functions defined by the standard into the underlying memory model. This memory model is the compiler developer's choice, but it is usually most convenient to use whatever functionality the target OS gives you. Hence, you see stacks and heaps often, but at least with regard to Fortran and C, which have nothing to do with the programming language.



+4


source


Sounds like you have some misconceptions. First of all, FORTRAN implementations in general (always in practice?) Use a stack. Classic FORTRAN cannot allocate variables on the stack, but it must use the stack to make procedure calls. Even with FORTRAN implementations that use static argument frames, they still create stack frames.



The heap is simply memory that is managed as it allows random allocations and freeing of memory. Some programming languages ​​use the heap implicitly, for example to manage dynamic strings and arrays (like BASIC). Other programming languages ​​allow the programmer to use the heap, but don't require it (like C). Some programming languages ​​usually do not use a heap for constructs available to the programmer (for example, Cobol, classic FORTRAN).

0


source







All Articles