Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
14 Views

allocatable linkeld list components and ram demand

Hi there,

I have a linked list class:

  Type :: LLEle !!the list element
    Integer :: Isval
    Type(LLEle_IS), Pointer :: next=>null()
  End type LLEle
  Type :: LLCon !!the list container
    Integer, Pointer :: ISOutPutUnit=>null()
    Integer :: ISLength=0
    Integer :: issubstat=0
    Character(:), allocatable :: CSMSG
    Type(LLEle), Pointer :: TLStart=>null(), TLEnd=>null(),&
      & TLRun=>null(), TLTmp=>null(), TLLastAdded=>null()
  contains
    Procedure, Pass :: Add => SubAddToList
    Procedure, Pass :: Insert => SubInsert
.......................
  End Type LLCon_Is

I noticed that changing "isval" to "allocatable" doubles the processing time (which is sort of reasonable), but also doubles the ram requirement of the list. Note that allocation of isval is done implicitly ("isval=input", not "Allocate(isval,source=input)").

I can imagine that without the allocatable keyword, the scalar is accessible through the memory address of the allocated list element, whereas with the allocatable keyword, the scalar will have an own memory address, in addition to the memory address of the pointer. this then will inturn have consequences for the access speed when searching for values because two addresses must be resolved. However, I am just guessing, so someone with a more profound understanding of the matter may clarify.

Any suggestions are much appreciated.

0 Kudos
1 Reply
Highlighted
Black Belt Retired Employee
14 Views

Only doubles? I would expect more. As an integer, IsVal takes 4 bytes per list element. As allocatable, each list element contains the descriptor for the allocatable value, which is many more, plus the allocated storage itself.

0 Kudos