Skip to end of metadata
Go to start of metadata

Gets a single memory block from the heap.

Files

lib_mem.h/lib_mem.c

Prototype

void  *Mem_HeapAlloc (CPU_SIZE_T   size,
                      CPU_SIZE_T   align,
                      CPU_SIZE_T  *poctets_reqd,
                      LIB_ERR     *perr);

Arguments

size

Size of requested memory block (in octets).

align

Alignment of requested memory block (in octets).

poctets_reqd

Pointer to a variable to …

Return the number of octets required to successfully allocate the memory block, if any errors;

Return 0, otherwise.

perr

Pointer to variable that will receive the return error code from this function:

LIB_MEM_ERR_NONE
LIB_MEM_ERR_INVALID_MEM_SIZE
LIB_MEM_ERR_INVALID_MEM_ALIGN
LIB_MEM_ERR_HEAP_EMPTY
LIB_MEM_ERR_HEAP_OVF

Returned Value

Pointer to memory block, if no errors;

Pointer to NULL, otherwise.

Required Configuration

Available only if LIB_MEM_CFG_ALLOC_EN is DEF_ENABLED in lib_cfg.h (see section 4-4).

Notes / Warnings

None.

Example Usage

          void        *pmem_blk;
          CPU_SIZE_T   octets_reqd;
          LIB_ERR      err;
           
          pmem_blk = Mem_HeapAlloc((CPU_SIZE_T) 100u,
                                   (CPU_SIZE_T)   4u,
                                   (CPU_SIZE_T)&octets_reqd,
                                   (LIB_ERR  *)&err);
           
          if (err != LIB_ERR_NONE) {
              printf("COULD NOT GET MEMORY BLOCK FROM HEAP.");
          }
  • No labels