akmalloc
 All Data Structures Files Functions Variables Typedefs Macros Pages
Typedefs | Functions
malloc.h File Reference
#include <stddef.h>

Go to the source code of this file.

Typedefs

typedef int(* ak_seg_cbk )(const void *p, size_t sz)
 

Functions

void * ak_malloc (size_t n)
 
void * ak_calloc (size_t n, size_t s)
 
void ak_free (void *p)
 
size_t ak_malloc_usable_size (const void *p)
 
void * ak_realloc (void *p, size_t newsz)
 
void * ak_memalign (size_t aln, size_t sz)
 
void * ak_aligned_alloc (size_t aln, size_t sz)
 
int ak_posix_memalign (void **pptr, size_t aln, size_t sz)
 
void ak_malloc_for_each_segment (ak_seg_cbk cbk)
 

Detailed Description

Date
Mar 01, 2016

Definition in file malloc.h.

Typedef Documentation

typedef int(* ak_seg_cbk)(const void *p, size_t sz)

Gets a pointer to a memory segment and its size.

Parameters
p;Pointer to segment memory.
sz;Number of bytes in the segment.
Returns
0 to stop iteration, non-zero to continue.

Definition at line 62 of file malloc.h.

Function Documentation

void* ak_aligned_alloc ( size_t  aln,
size_t  sz 
)

Attempt to allocate memory containing at least n bytes at an address which is a multiple of aln. aln must be a power of two. sz must be a multiple of aln.

Parameters
aln;The alignment
sz;The size for the allocation
Returns
0 on failure, else pointer to at least n bytes of memory at an aligned address.

Definition at line 3024 of file malloc.c.

void* ak_calloc ( size_t  n,
size_t  s 
)

Attempt to allocate zeroed memory, containing at least n x s bytes.

Parameters
n;Number of objects to zero.
s;The size for each object.
Returns
0 on failure, else pointer to at least s bytes of memory.

Definition at line 3011 of file malloc.c.

void ak_free ( void *  p)

Return memory to the allocator.

Parameters
p;Pointer to the memory to return.

Definition at line 3018 of file malloc.c.

void* ak_malloc ( size_t  n)

Attempt to allocate memory containing at least n bytes.

Parameters
n;The size for the allocation
Returns
0 on failure, else pointer to at least n bytes of memory.

Definition at line 3005 of file malloc.c.

void ak_malloc_for_each_segment ( ak_seg_cbk  cbk)

Iterate over all memory segments allocated.

Parameters
cbk;Callback that is given the address of a segment and its size.
See also
ak_seg_cbk.

Definition at line 3059 of file malloc.c.

size_t ak_malloc_usable_size ( const void *  p)

Return the usable size of the memory region pointed to by p.

Parameters
p;Pointer to the memory to determize size of.
Returns
The number of bytes that can be written to in the region.

Definition at line 3042 of file malloc.c.

void* ak_memalign ( size_t  aln,
size_t  sz 
)

Attempt to allocate memory containing at least n bytes at an address which is a multiple of aln. aln must be a power of two.

Parameters
aln;The alignment
sz;The size for the allocation
Returns
0 on failure, else pointer to at least n bytes of memory at an aligned address.

Definition at line 3036 of file malloc.c.

int ak_posix_memalign ( void **  pptr,
size_t  aln,
size_t  sz 
)

Attempt to allocate memory containing at least n bytes at an address which is a multiple of aln and assign the address to *pptr. aln must be a power of two and a multiple of sizeof(void*).

Parameters
pptr;The address where the memory address should be writted.
aln;The alignment
sz;The size for the allocation
Returns
0 on success, 12 if no more memory is available, and 22 if aln was not a power of two and a multiple of sizeof(void*)

Definition at line 3030 of file malloc.c.

void* ak_realloc ( void *  p,
size_t  newsz 
)

Attempt to grow memory at the region pointed to by p to a size newsz.

Parameters
p;Memory to grow
newsz;New size to grow to

This function will copy the old bytes to a new memory location if the old memory cannot be grown in place, and will free the old memory. If no more memory is available it will not destroy the old memory.

Returns
NULL if no memory is available, or a pointer to memory with at least newsz bytes.

Definition at line 3047 of file malloc.c.