Make room for need entries, keeping contents.
Capacity doubles when needed; new array starts at max(need, 64).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(inout), | allocatable | :: | a(:) |
Array. |
|
| integer(kind=int32), | intent(in) | :: | need |
Number of entries needed. |
subroutine grow_i32(a, need) !! Make room for `need` entries, keeping contents. !! !! Capacity doubles when needed; new array starts at `max(need, 64)`. ! Arguments integer(int32), allocatable, intent(inout) :: a(:) !! Array. integer(int32), intent(in) :: need !! Number of entries needed. integer(int32), allocatable :: tmp(:) integer(int32) :: cap if (.not. allocated(a)) then allocate (a(max(need, 64_int32))) return end if cap = int(size(a), int32) if (need <= cap) return allocate (tmp(max(need, 2*cap))) tmp(1:cap) = a call move_alloc(tmp, a) end subroutine grow_i32