Hello,
I'm working on a public release if a model using Fortran 9x and I'd like to design the code to support both static or dynamic memory management.
I've only seen one example of a code that supports something like this. It is implemented using preprocessors that look something like this:
The code would include some memory management control file with the following:
#ifdef STATIC
define NMEM_ N
define PTR_ # blank
#else
define NMEM_ :
define PTR_ ,pointer
The user supplies the following file to configure static memory:
#define N 100 # Example array size
#define STATIC
In the core code, you declare your variable as such:
real PTR_, dimension(NMEM_) :: x
Set STATIC during compilation, and it becomes
real, dimension(100) :: x
Unset STATIC (implicitly setting it to dynamic) and it becomes
real, pointer, dimension(:) :: x
and some later code allocates the memory.
This works perfectly fine, but I like to avoid using preprocessors if I can, and it does feel like a kludge to me. Is there a more standard solution to this problem, or is this how it is normally handled? Is there even much difference between static and dynamic compilations these days (keeping in mind that I will probably want to use as much memory as I can)?