initialization of a dynamic array
before a dynamic array can be used, it has to be initialized with this routine. the initial length provided here, can avoid reallocations and memory copying, if approximated correctly enough. if none is specified, the provided container initially will be of size 0.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dyn_intarray_type), | intent(out) | :: | me | |||
integer, | intent(in), | optional | :: | length |
subroutine init_da_int(me, length)
!-----------------------------------------------------------------
type(dyn_intarray_type), intent(out) :: me !< dynamic array to init
integer, intent(in), optional :: length !< initial length of the container
!-----------------------------------------------------------------
if (present(length)) then
me%containersize = length
else
me%containersize = zerolength
end if
! deallocate ...
if( allocated( me%val ) ) deallocate(me%val)
if( allocated( me%sorted ) ) deallocate(me%sorted)
! ... and reallocate
allocate(me%val(me%containersize))
allocate(me%sorted(me%containersize))
me%nvals = 0
end subroutine init_da_int