In my Fortran code, I want to use jagged arrays with multiple distribution levels. The sample code that I mean is
module nonsquare_matrix_mod
implicit none
type :: nonsquare_matrix
integer :: d
real*8, dimension(:), allocatable :: vector
end type nonsquare_matrix
type(nonsquare_matrix),dimension(:),allocatable :: mymatrix
end module nonsquare_matrix_mod
program nonsquare_matrix_test
use nonsquare_matrix_mod
implicit none
integer, parameter :: max_size=50
integer :: i
allocate(mymatrix(max_size))
do i=1,max_size
allocate(mymatrix(i) % vector(i))
end do
print *, "allocated"
end program
I want to implement this programming strategy to save memory. I know that the memory saved in this example is not too large, but for my actual project I work with much larger data structures. I was wondering if there are any dangers in this programming practice, such as data that is not stored permanently or is more prone to memory leaks. Or is it a useful way to save memory without many flaws? Thank.
source
share