YAZ  5.26.1
Data Structures | Macros | Functions | Variables
nmem.c File Reference

Implements Nibble Memory. More...

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stddef.h>
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/log.h>
#include <yaz/snprintf.h>

Go to the source code of this file.

Data Structures

struct  nmem_block
 
struct  nmem_control
 
struct  align
 

Macros

#define NMEM_CHUNK   (4*1024)
 
#define NMEM_ALIGN   (offsetof(struct align, u))
 

Functions

static void nmem_lock (void)
 
static void nmem_unlock (void)
 
static void free_block (struct nmem_block *p)
 
static struct nmem_blockget_block (size_t size)
 
void nmem_reset (NMEM n)
 releases memory associaged with an NMEM handle More...
 
void * nmem_malloc (NMEM n, size_t size)
 allocates memory block on NMEM handle More...
 
size_t nmem_total (NMEM n)
 returns size in bytes of memory for NMEM handle More...
 
void nmem_init_globals (void)
 
NMEM nmem_create (void)
 returns new NMEM handle More...
 
void nmem_destroy (NMEM n)
 destroys NMEM handle and memory associated with it More...
 
void nmem_transfer (NMEM dst, NMEM src)
 transfers memory from one NMEM handle to another More...
 
int nmem_get_status (char *dst, size_t l)
 returns memory status for NMEM - as XML More...
 

Variables

static size_t no_nmem_handles = 0
 
static size_t no_nmem_blocks = 0
 
static size_t nmem_allocated = 0
 
static int log_level = 0
 
static int log_level_initialized = 0
 

Detailed Description

Implements Nibble Memory.

This is a simple and fairly wasteful little module for nibble memory allocation.

Definition in file nmem.c.

Macro Definition Documentation

◆ NMEM_ALIGN

#define NMEM_ALIGN   (offsetof(struct align, u))

Definition at line 71 of file nmem.c.

Referenced by nmem_malloc().

◆ NMEM_CHUNK

#define NMEM_CHUNK   (4*1024)

Definition at line 39 of file nmem.c.

Referenced by get_block().

Function Documentation

◆ free_block()

static void free_block ( struct nmem_block p)
static

◆ get_block()

static struct nmem_block* get_block ( size_t  size)
static

◆ nmem_create()

NMEM nmem_create ( void  )

◆ nmem_destroy()

void nmem_destroy ( NMEM  n)

◆ nmem_get_status()

int nmem_get_status ( char *  dst,
size_t  l 
)

returns memory status for NMEM - as XML

Parameters
dstbuffer for result
lsize of buffer (200 should suffice)
Returns
0 if OK
-1 on failure

Definition at line 229 of file nmem.c.

References nmem_allocated, nmem_lock(), nmem_unlock(), no_nmem_blocks, no_nmem_handles, and yaz_snprintf().

◆ nmem_init_globals()

void nmem_init_globals ( void  )

Definition at line 174 of file nmem.c.

References nmem_lock(), and nmem_unlock().

Referenced by yaz_init_globals().

◆ nmem_lock()

static void nmem_lock ( void  )
static

◆ nmem_malloc()

void* nmem_malloc ( NMEM  n,
size_t  size 
)

◆ nmem_reset()

void nmem_reset ( NMEM  n)

releases memory associaged with an NMEM handle

Parameters
nNMEM handle

Definition at line 129 of file nmem.c.

References nmem_control::blocks, free_block(), log_level, nmem_block::next, nmem_control::total, and yaz_log().

Referenced by ccl_stop_words_tree(), cql_parser_stream(), nmem_destroy(), odr_reset(), yaz_marc_reset(), and yaz_record_conv_reset().

◆ nmem_total()

size_t nmem_total ( NMEM  n)

returns size in bytes of memory for NMEM handle

Returns
number of bytes

Definition at line 169 of file nmem.c.

References nmem_control::total.

Referenced by odr_total().

◆ nmem_transfer()

void nmem_transfer ( NMEM  dst,
NMEM  src 
)

transfers memory from one NMEM handle to another

Parameters
srcsource NMEM handle
dstdestination NMEM handle

Definition at line 216 of file nmem.c.

References nmem_control::blocks, nmem_block::next, and nmem_control::total.

Referenced by handle_srw_response(), handle_srw_scan_response(), handle_Z3950_records(), handle_Z3950_scan_response(), and process_searchRequest().

◆ nmem_unlock()

static void nmem_unlock ( void  )
static

Variable Documentation

◆ log_level

int log_level = 0
static

Definition at line 73 of file nmem.c.

Referenced by free_block(), get_block(), nmem_create(), and nmem_reset().

◆ log_level_initialized

int log_level_initialized = 0
static

Definition at line 74 of file nmem.c.

Referenced by nmem_create().

◆ nmem_allocated

size_t nmem_allocated = 0
static

Definition at line 37 of file nmem.c.

Referenced by free_block(), get_block(), and nmem_get_status().

◆ no_nmem_blocks

size_t no_nmem_blocks = 0
static

Definition at line 36 of file nmem.c.

Referenced by free_block(), get_block(), and nmem_get_status().

◆ no_nmem_handles

size_t no_nmem_handles = 0
static

Definition at line 35 of file nmem.c.

Referenced by nmem_create(), nmem_destroy(), and nmem_get_status().