freex()

Purpose

Releases alllocate memory back to, or adds new memory to, the heap

Syntax

void freex(ANY *ptr,size_t size)

Parameters

ANY *ptr

Pointer to memory area size_t size

 

size_t size

Number of bytes to add to heap

Description

This function releases allocated memory back to the heap, or adds new memory to the heap (which is created if it did not already exist). The number of bytes specified by the size parameter is added to the heap. Any region of memory can be added to the heap with freex(), including for example, static variables that are no longer required.

From 4.620 freex() always assumes it is safe to round up any size passed to it to the nearest acceptable size (determined by calling mallocxable()) , on the assumption that this size was actually allocated by a previous call to mallocx(). If adding memory from elsewhere you must be careful to round down the size first, (by calling mallocxable() until it returns a size no geater than the actual size of the block you are adding to the heap). If you require memory to be properly aligned, you need to be careful to add only aligned memory to the heap.

When memory is freed, the new region is combined with contiguous free regions if there are any.

Return values

None

See also

freep(), mallocx()

Example

See cache_find() for an example of usage