Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

lib_mem.h/lib_mem.c

Prototype

Code Block
languagecpp
          void  Mem_PoolBlkFree (MEM_POOL  *pmem_pool,
                                 void      *pmem_blk,
                                 LIB_ERR   *perr);


Arguments

pmem_pool

Pointer to memory pool to free memory block to.

...

Notes / Warnings

None.

Example Usage

Code Block
languagecpp
MEM_POOL     AppMemPool;
CPU_SIZE_T   octets_reqd;
void        *pmem_blk;
LIB_ERR      err;


Mem_PoolCreate((MEM_POOL       *)&AppMemPool,
             (void           *)  0,              /* Create pool from heap   ...                    */
             (CPU_SIZE_T      )  0u,
             (MEM_POOL_BLK_QTY) 10u,             /* ... with 10 blocks      ...                    */
             (CPU_SIZE_T      )100u,             /* ... of  100 octets each ...                    */
             (CPU_SIZE_T      )  4u,             /* ... and align each block to a 4-byte boundary. */
             (CPU_SIZE_T     *)&octets_reqd,
             (LIB_ERR        *)&err);

if (err != LIB_ERR_NONE) {
  printf("COULD NOT CREATE MEMORY POOL.");
  if (err == LIB_MEM_ERR_HEAP_EMPTY) {
      printf("Heap empty   ... %u more octets needed.", octets_reqd);
  }
    return;
}

                                                 /* Get an 80-byte memory block from the pool.     */
pmem_blk = Mem_PoolBlkGet(&AppMemPool, 80u, &err);
if (err != LIB_ERR_NONE) {
  printf("COULD NOT GET MEMORY BLOCK FROM MEMORY POOL.");
    return;
}
                                                 /* Free   80-byte memory block back to  pool.     */
Mem_PoolBlkFree(&AppMemPool, pmem_blk, &err);
if (err != LIB_ERR_NONE) {
    printf("COULD NOT FREE MEMORY BLOCK TO MEMORY POOL.");
    return;
}