DFREE Examples


Example 1:

 

pDimA

DIM

^

pDimB

DIM

^

.

 

 

  

DMAKE

pDimA,1000000

  

.

 

  

.program executes

 

  

.

 

  

DFREE

pDimA ;DIM variable buffer is freed

  

 

         ;pDimA pointer is cleared

  

STOP

 

 

This is a simple example that creates a one million byte variable and then releases it.

Example 2:

 

pDimA

DIM

^

pDimB

DIM

^

.

 

 

  

DMAKE

pDimA,1000000

  

MOVEPTR

pDimA,pDimB ;Both point to DIM variable

  

.

 

  

.program executes

 

  

.

 

  

DFREE

pDimB ;DIM variable buffer is freed

  

 

         ;Both pDimA & pDimB are cleared

  

STOP

 

 

This example program creates a one million byte variable. It then assigns a second point to the newly acquired space. Execution of the DFREE on the second variable releases the memory and clears the second variable but also clears the first variable. This is done because to the location it references is no longer valid.

Example 3:

 

pDimA

DIM

^

.

 

 

  

DMAKE

pDimA,1000000

  

CALL

xFunc using pDimA

  

.

 

  

.program executes

  

.

 

  

DFREE

pDimA ;DIM variable buffer is freed

  

 

         ;Both pDimA & pDimC are cleared

  

STOP

 

.

 

 

pDimC

DIM

^

.

 

 

xFunc

LROUTINE

pDimC

  

.

 

  

.pDimC points to DIM variable created by DMAKE

  

.

 

  

RETURN

 

 

This example creates a test varible. The pointer to the variable is then passed to the LROUTINE where it is received into a second pointer variable. Upon exit from the routine, both pointer variables reference the same memory location. Upon execution of the DFREE instruction, both pointers are cleared and the memory released.

 



PL/B Language Reference DESTROY Example DIM Examples