Heapfree.rpg

 
     d DynArr          s               z   dim(32767)
     d                                     based(pDynArr)

     d Size            s             10i 0
     d i               s             10i 0
     d reply           s              1


      /Free

       //  Allocate storage for 100 array elements.

        //  First calculate how many bytes are needed for 100 elements.
        //  Note, %size(NameOfArray) returns the number of bytes in one
        //  element of the array.

          Size = 100 * %size(DynArr);


         //  Allocate storage

          pDynArr = %Alloc(Size);


       //  Fill in array elements
       //  1-100.

          for i = 1 to 100;
            DynArr(i) = %Time;
          endfor;


       //  Does it work?
          dsply  DynArr(50)  ' '  reply;


       //  Expand array to 200 elements.

         //  Calculate bytes needed.

          Size = 200 * %size(DynArr);


         //  Allocate storage. Note, the Realloc op-code may move the
         //  original block of storage to a new location, but it will
         //  also copy the original data to the new location.
          pDynArr = %Realloc(pDynArr: Size);


       //  Fill in array elements
       //  101-200.

          for i = 101 to 200;
            DynArr(i) = %Time;
          endfor;

          dsply  DynArr(150)  ' '  reply;


       //  Free array storage.

          Dealloc  pDynArr;

       //  Array DynArr can no longer be used.


          *InLR = '1';
          return;

-ADS BY GOOGLE

SearchDataCenter

Close