ELinks 0.18.0
memory.h File Reference
#include <sys/types.h>
#include <stddef.h>
#include <string.h>
Include dependency graph for memory.h:

Macros

#define ALLOC_MAXTRIES   3
 Max.
 
#define ALLOC_DELAY   3
 Delay in seconds between each alloc try.
 
#define fmem_alloc(x)   mem_alloc(x)
 
#define fmem_free(x)   mem_free(x)
 
#define mem_mmap_alloc(x)   mem_alloc(x)
 Cygwin wants some size_t definition here... let's try to make it happy then.
 
#define mem_mmap_free(x, y)   mem_free(x)
 
#define mem_mmap_realloc(x, y, z)   mem_realloc(x, z)
 
#define intdup(i)   intdup__(i)
 
Maybe-free macros
Todo
TODO: Think about making what they do more obvious in their identifier, they could be obfuscating their users a little for the newcomers otherwise.
#define mem_free_set(x, v)   do { if (*(x)) mem_free(*(x)); *(x) = (v); } while (0)
 
#define mem_free_if(x)   do { void *p = (x); if (p) mem_free(p); } while (0)
 

Functions

void * mem_alloc (size_t)
 
void * mem_calloc (size_t, size_t)
 
void mem_free (void *)
 
void * mem_realloc (void *, size_t)
 
static int * intdup__ (int i)
 

Granular memory allocation.

The granularity used by the aligned memory functions below must be a mask with all bits set from but not including the most significant bit and down.

So if an alignment of 256 is wanted use 0xFF.

#define ALLOC_GR   0x100
 The 'old' style granularity.
 
#define ALIGN_MEMORY_SIZE(x, gr)   (((x) + (gr)) & ~(gr))
 
#define mem_align_alloc(ptr, old, new_, mask)    mem_align_alloc__((void **) ptr, old, new_, sizeof(**ptr), mask)
 
static void * mem_align_alloc__ (void **ptr, size_t old, size_t new_, size_t objsize, size_t mask)
 

Macro Definition Documentation

◆ ALIGN_MEMORY_SIZE

#define ALIGN_MEMORY_SIZE ( x,
gr )   (((x) + (gr)) & ~(gr))

◆ ALLOC_DELAY

#define ALLOC_DELAY   3

Delay in seconds between each alloc try.

◆ ALLOC_GR

#define ALLOC_GR   0x100

The 'old' style granularity.

XXX: Must be power of 2

◆ ALLOC_MAXTRIES

#define ALLOC_MAXTRIES   3

Max.

number of retry in case of memory allocation failure.

◆ fmem_alloc

#define fmem_alloc ( x)    mem_alloc(x)

◆ fmem_free

#define fmem_free ( x)    mem_free(x)

◆ intdup

#define intdup ( i)    intdup__(i)

◆ mem_align_alloc

#define mem_align_alloc ( ptr,
old,
new_,
mask )    mem_align_alloc__((void **) ptr, old, new_, sizeof(**ptr), mask)

◆ mem_free_if

#define mem_free_if ( x)    do { void *p = (x); if (p) mem_free(p); } while (0)

◆ mem_free_set

#define mem_free_set ( x,
v )   do { if (*(x)) mem_free(*(x)); *(x) = (v); } while (0)

◆ mem_mmap_alloc

#define mem_mmap_alloc ( x)    mem_alloc(x)

Cygwin wants some size_t definition here... let's try to make it happy then.

Hrmpf.

◆ mem_mmap_free

#define mem_mmap_free ( x,
y )   mem_free(x)

◆ mem_mmap_realloc

#define mem_mmap_realloc ( x,
y,
z )   mem_realloc(x, z)

Function Documentation

◆ intdup__()

static int * intdup__ ( int i)
inlinestatic

◆ mem_align_alloc__()

static void * mem_align_alloc__ ( void ** ptr,
size_t old,
size_t new_,
size_t objsize,
size_t mask )
inlinestatic

◆ mem_alloc()

void * mem_alloc ( size_t )

◆ mem_calloc()

void * mem_calloc ( size_t ,
size_t  )

◆ mem_free()

void mem_free ( void * )

◆ mem_realloc()

void * mem_realloc ( void * ,
size_t  )