Skip to content

File mem_alloc.h

FileList > docs > sw > include > opae > mem_alloc.h

Go to the source code of this file.

  • #include <stdint.h>

Classes

Type Name
struct mem_alloc
struct mem_link
Provides an API for allocating/freeing a logical address space.

Public Functions

Type Name
int mem_alloc_add_free (struct mem_alloc * m, uint64_t address, uint64_t size)
Add a memory region to an allocator.
void mem_alloc_destroy (struct mem_alloc * m)
Destroy a memory allocator object.
int mem_alloc_get (struct mem_alloc * m, uint64_t * address, uint64_t size)
Allocate memory.
void mem_alloc_init (struct mem_alloc * m)
Initialize a memory allocator object.
int mem_alloc_put (struct mem_alloc * m, uint64_t address)
Free memory.

Public Functions Documentation

function mem_alloc_add_free

Add a memory region to an allocator.

int mem_alloc_add_free (
    struct mem_alloc * m,
    uint64_t address,
    uint64_t size
) 

The memory region is added to the allocatable space and is immediately ready for allocation.

Parameters:

  • m The memory allocator object.
  • address The beginning address of the memory region.
  • size The size of the memory region.

Returns:

Non-zero on error. Zero on success.

Example struct mem_alloc m;

mem_alloc_init(&m);

if (mem_alloc_add_free(&m, 0x4000, 4096)) { // handle error }

function mem_alloc_destroy

Destroy a memory allocator object.

void mem_alloc_destroy (
    struct mem_alloc * m
) 

Frees all of the allocator's internal resources.

Parameters:

  • m The address of the memory allocator to destroy.

function mem_alloc_get

Allocate memory.

int mem_alloc_get (
    struct mem_alloc * m,
    uint64_t * address,
    uint64_t size
) 

Retrieve an available memory address for a free block that is at least size bytes.

Parameters:

  • m The memory allocator object.
  • address The retrieved address for the allocation.
  • size The request size in bytes.

Returns:

Non-zero on error. Zero on success.

Example struct mem_alloc m; uint64_t addr = 0;

mem_alloc_init(&m);

if (mem_alloc_add_free(&m, 0x4000, 4096)) { // handle error }

...

if (mem_alloc_get(&m, &addr, 4096)) { // handle allocation error }

function mem_alloc_init

Initialize a memory allocator object.

void mem_alloc_init (
    struct mem_alloc * m
) 

After the call, the allocator is initialized but "empty". To add allocatable memory regions, further initialize the allocator with mem_alloc_add_free().

Parameters:

  • m The address of the memory allocator to initialize.

function mem_alloc_put

Free memory.

int mem_alloc_put (
    struct mem_alloc * m,
    uint64_t address
) 

Release a previously-allocated memory block.

Parameters:

  • m The memory allocator object.
  • address The address to free.

Returns:

Non-zero on error. Zero on success.

Example struct mem_alloc m; uint64_t addr = 0;

mem_alloc_init(&m);

if (mem_alloc_add_free(&m, 0x4000, 4096)) { // handle error }

...

if (mem_alloc_get(&m, &addr, 4096)) { // handle allocation error }

...

if (mem_alloc_put(&m, addr)) { // handle free error }


The documentation for this class was generated from the following file docs/sw/include/opae/mem_alloc.h