Chapter Contents |
Previous |
Next |
hpdestroy |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
IMPLEMENTATION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <multheap.h> void *hpdestroy(_heap_id heapid);
DESCRIPTION |
hpdestroy
destroys a heap
and returns all its memory back to the operating system. Any further use of
memory allocated from the heap will be invalid.
RETURN VALUE |
hpdestroy
returns a code
indicating success (0) or failure (-1) of the operation.
IMPLEMENTATION |
The control information assocated with the heap is freed.
Be sure not to call hpdestroy
for a shared
heap that may be in use by another task.
EXAMPLE |
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <multheap.h> main() { _heap_attr attr; _heap_id id1; DCB_t *input, *output; DECB_t input_DECB, output_DECB; char *buf; int count = 0; int err; input = osbdcb(0); memcpy(input->DCBDDNAM, "INPUT ", 8); if (osbopen(input, "input")) { puts("Input open failed."); exit(16); } output = osbdcb(out_exlst); /* Copy output file characteristics from input. */ output->DCBRECFM = input->DCBRECFM; output->DCBLRECL = input->DCBLRECL; output->DCBBLKSI = input->DCBBLKSI; memcpy(output->DCBDDNAM, "OUTPUT ", 8); if (osbopen(output, "output")) { puts("Output open failed."); osbclose(input, "", 1); exit(16); } // Get a below the line heap for use in BSAM I/O hpattr(&attr); attr.amode = HPLOC_BELOW; attr.flags = HPATTR_SIGOK + HPATTR_NOABEND; attr.initial = 4000; id1 = hpcreate(&attr, "heap below"); if (!id1) { Log("error in hpcreate.\n"); return -1; } buf = hpalloc(id1, input->DCBBLKSI); for (;;) { buf = hpalloc(id1, input->DCBBLKSI); osread(input_DECB, input, buf, 0); if ((err = oscheck(input_DECB)) != 0) { if (err != -1) puts("Input error."); break; } oswrite(output_DECB, output, buf, 0); if (oscheck(output_DECB) != 0) { if (full) puts("Output file full."); else puts("Output error."); break; } ++count; } /* Rather than freeing all the records, just free the entire heap. */ hpdestroy(id1); }
RELATED FUNCTIONS |
hpcreate
, hppoolcreate
SEE ALSO |
"Memory Allocation Functions" in Chapter 2, "Function Categories" of the SAS/C Library Reference, Volume 1.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.