Sunday, 17 September 2017

%ALLOC Example

      * Program     :·AllocR
      * Description :·%Alloc() Example
      *
      * %Alloc()
      * Input       :·Memory size(positive integer) to be allocated
      * Output      :·Pointer to Allocated memory
      *
      * Note        :·dynamically allocated memory should be set free
      *               when not required, else it will cause memory leak
      *
      *==========================================================
      *
     D Var1            S             20    Based(Ptr)

     D Ptr             S               *

     C
      /Free
           Ptr = %Alloc(5) ;
           Dealloc Ptr ;

           Ptr = %Alloc(2*2 + 1) ;

           Var1 = 'Allocated' ;
           Dsply Var1 ;

           Dealloc Ptr ;
      /End-Free
     C                   SetOn                                        LR

No comments:

Post a Comment