Chapter Contents

Previous

Next
hpalloc

hpalloc



Allocate Memory from Heap


SYNOPSIS
DESCRIPTION
RETURN VALUE
ERRORS
DIAGNOSTICS
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <multheap.h>
void *hpalloc(_heap_id heapid, size_t size);


DESCRIPTION

hpalloc allocates a block of dynamic memory of the size specified by size from a heap indicated by heapid, which was returned by hpcreate when it was initialized.


RETURN VALUE

hpalloc returns the address of the first character of the new block of memory. The allocated block is suitably aligned for storage of any type of data.


ERRORS

User ABEND 1205 or 1206 may occur if memory management data areas are overlaid.


DIAGNOSTICS

If adequate memory is not available, the heapid is invalid, or if 0 bytes are requested, NULL is returned.


IMPLEMENTATION

See malloc for a description of normal memory allocation. hpalloc is, in effect, the same as calling hppush(heapid), malloc(size), hppop().


EXAMPLE

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <multheap.h>
char *source, *copy;
main()
{
   source = "A simple line for the hpalloc example ";

   /* Allocate space for a copy for source. */
   copy = hpalloc(_HEAP_STD, strlen(source) + 1);

   /* Copy if there is space. */
   if (copy)
   {
      strcpy(copy,source);
      puts(copy);
   }
   else puts("hpalloc failed to allocate memory for copy.");
}


RELATED FUNCTIONS

malloc, pool, 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.