I don’t think it would change anything. The memory overhead is not because of the derived type encapsulation, but because of the internal descriptor that comes with a pointer or allocatable array. From what I can see, the descriptor of a 1D array is 64 bytes large with gfortran, and 72 bytes with ifx.
Using a type(c_ptr)
would reduce the memory footprint to 8 bytes, but the code would be more complex and probably less efficient (with many calls to c_loc()
and c_f_pointer()
. Alternatively, the whole hashmap library could be written in C, with wrapper routines for Fortran.
PS: the estimations by Grok look fairly wrong
Edit: the whole chaining_map_entry_type
storage size is 112 bytes in gfortran / 224 bytes in ifx.
hash_val: 8 / 8
key: 64 / 72
other: 24 / 128
inmap: 8 / 8
next: 8 / 8