regional.c File Reference

Regional allocator. More...

#include "config.h"
#include "util/log.h"
#include "util/regional.h"

Defines

#define ALIGN_UP(x, s)   (((x) + s - 1) & (~(s - 1)))
 increase size until it fits alignment of s bytes
#define ALIGNMENT   (sizeof(uint64_t))
 what size to align on; make sure a char* fits in it.
#define REGIONAL_CHUNK_SIZE   8192
 Default reasonable size for chunks.
#define REGIONAL_LARGE_OBJECT_SIZE   2048
 Default size for large objects - allocated outside of chunks.

Functions

struct regionalregional_create ()
 Create a new regional.
static void regional_init (struct regional *r)
 init regional struct with first block
struct regionalregional_create_custom (size_t size)
 Create a new region, with custom settings.
void regional_free_all (struct regional *r)
 Free all memory associated with regional.
void regional_destroy (struct regional *r)
 Destroy regional.
void * regional_alloc (struct regional *r, size_t size)
 Allocate size bytes of memory inside regional.
void * regional_alloc_init (struct regional *r, const void *init, size_t size)
 Allocate size bytes of memory inside regional and copy INIT into it.
void * regional_alloc_zero (struct regional *r, size_t size)
 Allocate size bytes of memory inside regional that are initialized to 0.
char * regional_strdup (struct regional *r, const char *string)
 Duplicate string and allocate the result in regional.
static size_t count_chunks (struct regional *r)
 reasonably slow, but stats and get_mem are not supposed to be fast count the number of chunks in use
static size_t count_large (struct regional *r)
 also reasonably slow, counts the number of large objects
void regional_log_stats (struct regional *r)
 Debug print regional statistics to log.
size_t regional_get_mem (struct regional *r)
 get total memory size in use by region


Detailed Description

Regional allocator.

Allocates small portions of of larger chunks.


Define Documentation

#define ALIGNMENT   (sizeof(uint64_t))

what size to align on; make sure a char* fits in it.

Referenced by regional_alloc(), regional_init(), and regional_log_stats().

#define REGIONAL_LARGE_OBJECT_SIZE   2048

Default size for large objects - allocated outside of chunks.

Referenced by regional_alloc(), and regional_log_stats().


Function Documentation

struct regional* regional_create (  )  [read]

struct regional* regional_create_custom ( size_t  size  )  [read]

Create a new region, with custom settings.

Parameters:
size,: length of first block.
Returns:
: newly allocated regional.

References regional::first_size, log_assert, and regional_init().

Referenced by alloc_reg_obtain(), libworker_setup(), prealloc_blocks(), regional_create(), and worker_init().

void regional_free_all ( struct regional r  ) 

Free all memory associated with regional.

Only keeps the first block with the regional inside it.

Parameters:
r,: the region.

References regional::large_list, regional::next, and regional_init().

Referenced by acl_list_apply_cfg(), alloc_reg_release(), answer_from_cache(), answer_norec_from_cache(), dstest_entry(), mesh_run(), perf_encode(), regional_destroy(), val_verify_rrset(), and verifytest_entry().

void regional_destroy ( struct regional r  ) 

void* regional_alloc ( struct regional r,
size_t  size 
)

void* regional_alloc_init ( struct regional r,
const void *  init,
size_t  size 
)

Allocate size bytes of memory inside regional and copy INIT into it.

The memory is deallocated when region_free_all is called for this region.

Parameters:
r,: the region.
init,: to copy.
size,: number of bytes.
Returns:
: pointer to memory allocated.

References regional_alloc().

Referenced by anchor_new_ta(), anchor_new_ta_key(), assemble_it(), copy_rrset(), create_msg(), delegpt_add_ns(), delegpt_set_name(), dns_copy_msg(), forwards_insert(), gen_dns_msg(), hints_insert(), insert_rr(), key_entry_copy_toregion(), key_entry_create_rrset(), key_entry_get_rrset(), key_entry_setup(), lz_find_create_node(), mesh_state_add_reply(), mesh_state_create(), nsec3_calc_b32(), nsec3_hash_test_entry(), process_ds_response(), regional_strdup(), repinfo_copy_rrsets(), synth_dname_msg(), and val_new().

void* regional_alloc_zero ( struct regional r,
size_t  size 
)

Allocate size bytes of memory inside regional that are initialized to 0.

The memory is deallocated when region_free_all is called for this region.

Parameters:
r,: the region.
size,: number of bytes.
Returns:
: pointer to memory allocated.

References regional_alloc().

Referenced by lz_find_create_node(), and new_local_rrset().

char* regional_strdup ( struct regional r,
const char *  string 
)

Duplicate string and allocate the result in regional.

Parameters:
r,: the region.
string,: null terminated string.
Returns:
: pointer to memory allocated.

References regional_alloc_init().


Generated on Sun Sep 21 16:23:30 2008 for unbound by  doxygen 1.5.6