BRL-CAD
heap.c File Reference
#include "common.h"
#include <stdlib.h>
#include "bu/debug.h"
#include "bu/log.h"
#include "bu/malloc.h"
#include "bu/parallel.h"
#include "bu/vls.h"
Include dependency graph for heap.c:

Go to the source code of this file.

Data Structures

struct  heap
 
struct  cpus
 

Macros

#define HEAP_BINS   256
 
#define HEAP_PAGESIZE   (HEAP_BINS * 256)
 

Functions

bu_heap_func_t bu_heap_log (bu_heap_func_t log)
 
void * bu_heap_get (size_t sz)
 
void bu_heap_put (void *ptr, size_t sz)
 

Macro Definition Documentation

#define HEAP_BINS   256

This number specifies the range of byte sizes to support for fast memory allocations. Any request outside this range will get passed to bu_calloc().

1-to-HEAP_BINS byte size allocations are allocated in PAGESIZE chunks as they are requested. There's minimal penalty for making this arbitrarily large except where there are very few allocations (each size will allocate at least one page). PAGESIZE should be some multiple larger than HEAP_BINS.

Embedded or memory-constrained environments probably want to set this a lot smaller than the default.

Definition at line 45 of file heap.c.

#define HEAP_PAGESIZE   (HEAP_BINS * 256)

This specifies how much memory we should preallocate for each allocation size. Note that this number should be some multiple of HEAP_BINS and system page size in order to be useful. Ideally sized to keep the allocation size with the most requests down to single-digit page counts. Testing showed a 1M page size was very effective at eliminating allocation overhead.

Embedded or memory-constrained environments probably want to set this a lot smaller than the default.

Definition at line 58 of file heap.c.