Auto De-Fragmenting Memory Pool

The ADM Pool module manages memory dynamically using a fixed-size buffer. It provides functions to allocate and free memory blocks efficiently while keeping track of them with a linked list.

Key Features:

  • Initialization: Sets up the memory pool with a buffer and size.

  • Dynamic Allocation: Allocates blocks of memory as needed.

  • Deallocation: Frees memory and adjusts the remaining blocks to optimize space.

Auto De-Fragmenting Memory Pool Header

Documentation from the relevant header as follows:

Auto De-fragmenting Memory Pool.

This file contains a collection of functions about Auto De-fragmenting Memory Pool

Author

Embien RAPIDSEA Team

Copyright

Embien Technologies India Pvt. Ltd.

Typedefs

typedef struct tag_rs_adm_pool_info rs_adm_pool_info_t

Structure to adm pool information.

typedef struct tag_rs_adm_alloc_info rs_adm_alloc_info_t

Structure to adm alloc information.

Functions

rs_ret_val_t rs_adm_pool_init(rs_adm_pool_info_t *ptr_pool, void *ptr_buf, uint32_t u32_size, uint32_t u32_alignment)

Initializes the pool with the given buffer.

This function initializes the pool with the given buffer

Parameters:
  • ptr_pool[out] - Pointer to the rs_adm_pool_info_t

  • ptr_buf[out] - Pointer to the buffer used in rs_adm_pool_info_t

  • u32_size[in] - Size of the buffer

  • u32_alignment[in] - Alignment for buffer management

Returns:

0 on success or error code

rs_ret_val_t rs_adm_alloc(rs_adm_pool_info_t *ptr_pool, rs_adm_alloc_info_t *ptr_alloc_mem, uint32_t u32_size)

Allocates the memory according to size and add it in linked list.

This function Allocates the memory according to size and add it in linked list

Parameters:
  • ptr_pool[out] - Pointer to the rs_adm_pool_info_t

  • ptr_alloc_mem[out] - Pointer to the rs_adm_alloc_info_t

  • u32_size[in] - Size of the buffer

Returns:

0 on success or error code

rs_ret_val_t rs_adm_free(rs_adm_pool_info_t *ptr_pool, rs_adm_alloc_info_t *ptr_alloc_mem)

Free the memory and add remove from the linked list.

This function free the memory and add remove from the linked list

Parameters:
  • ptr_pool[out] - Pointer to the rs_adm_pool_info_t

  • ptr_alloc_mem[out] - Pointer to the rs_adm_alloc_info_t

Returns:

0 on success or error code

struct tag_rs_adm_pool_info
#include <rs_adm_pool.h>

Structure to adm pool information.

Public Members

void *ptr_base

Pointer to the buffer.

uint32_t size

Size of the buffer.

void *ptr_list_head

Head of the Single linked list of all allocations.

uint32_t alignment

Memory Alignment value.

struct tag_rs_adm_alloc_info
#include <rs_adm_pool.h>

Structure to adm alloc information.

Public Members

void *ptr_alloc

Pointer to the allocated buffer.

rs_adm_alloc_info_t *ptr_next_alloc

Pointer to the next memory in list.

uint32_t size

Size of the current holding memory.