Re: A basic question about linked list



veda wrote:


I want to know the correct procedure for deallocating memory that gets
allocated during creation of a linked list (I am using CVF).

(snip)

type curve
type(face_1d):: facet
type(curve), pointer::next
end type curve

type(curve), pointer:: head
type(curve), pointer::tail
type(curve), pointer::ptr_temp
(snip)

Later in the code, I want to re-define the curve identified by
"head" (e.g. all together different set of segments). What do I need
to do to deallocate memory correctly for the previously defined curve
before starting to define the new curve?

If is usual to pointer assign NULL() to the next pointer of
the last element in the list, which usually means you don't need
a tail pointer. In any case, you go down the list, saving the
next pointer in a temporary pointer, deallocating the current
element, and then copying the temporary to the current pointer.

Maybe something like:

do while(associated(head))
ptr_temp => head%next
deallocate(head)
head => ptr_temp
enddo
head => null()

If the list isn't terminated with a null pointer, you could use

do while(.not.associated(head,tail))

but null termination is better.

-- glen

.



Relevant Pages

  • Re: A basic question about linked list
    ... type, pointer:: head ... "head". ... to do to deallocate memory correctly for the previously defined curve ...
    (comp.lang.fortran)
  • Re: Still more linked list magic :-)
    ... if pointer deallocation succeeded ... TYPE(my_pointer), POINTER:: current! ... Check if the head of the list is allocated, ... print *, 'before calling dealloc_list:' ...
    (comp.lang.fortran)
  • Still more linked list magic :-)
    ... if pointer deallocation succeeded ... TYPE(my_pointer), POINTER:: current! ... Check if the head of the list is allocated, ... print *, 'before calling dealloc_list:' ...
    (comp.lang.fortran)
  • [RFC][PATCH] Improve readability by hiding read_barrier_depends() calls
    ... it is sometimes difficult to figure out which pointer is ... extern void rcu_check_callbacks(int cpu, int user); ... #define list_for_each_safe_rcu(pos, n, head) \ ... * Double linked lists with a single pointer list head. ...
    (Linux-Kernel)
  • Re: Skybucks Warrior: CleanTheHouseV2
    ... org head ... contains the pointer for clearing so when it overwrites the pointer ... trail of processes that makes your warrior stronger. ... Location 'gate' is incremented continuously, ...
    (rec.games.corewar)