Previous: libefi-argp, Up: libefi


5.1.5 Memory Management

Besides the functions that the uefi makes available for memory management, the `efi' library provides a set of convenience functions to make it easier to allocate and free memory.

To allocate pooled memory the efi_malloc function can be used. The difference from efi_allocate_pool is that efi_malloc returns a pointer to the allocated memory. Memory allocated with efi_malloc is like any other pooled memory freed with efi_free_pool.

— Function: void* efi_malloc (efi_memory_type_t type, efi_uint_t size)

Allocate size bytes of pooled memory from memory pool specified by type. Return pointer to allocated memory, or NULL if memory could not be allocated.

The efi_palloc and efi_pfree functions operate on page memory, meaning that the handle non-pooled memory. efi_palloc allocates memory and sets it to a specified memory type, using the given allocation scheme. efi_pfree releases memory allocated with either efi_palloc or efi_allocate_pages.

— Function: void* efi_palloc (efi_allocate_type_t allocate_type, efi_memory_type_t mt, efi_uint_t size)

Allocate memory using allocation scheme allocate_type and memory type mt. Allocate size bytes of memory.

— Function: void efi_pfree (void *p, efi_uint_t size)

Free pages pointed to by p. size is the number of bytes allocated.