YAZ  5.34.0
Macros | Typedefs | Functions
nmem.h File Reference

Header for Nibble Memory functions. More...

#include <stddef.h>
#include <yaz/yconfig.h>

Go to the source code of this file.

Macros

#define NMEM_64   1
 Set to 1 if YAZ BER integer is 64-bit ; 0 otherwise. More...
 
#define NMEM_INT_PRINTF   "%lld"
 

Typedefs

typedef struct nmem_controlNMEM
 NMEM handle (an opaque pointer to memory) More...
 
typedef long long int nmem_int_t
 
typedef int nmem_bool_t
 BER/utility boolean. More...
 

Functions

void nmem_reset (NMEM n)
 releases memory associaged with an NMEM handle More...
 
size_t nmem_total (NMEM n)
 returns size in bytes of memory for NMEM handle More...
 
char * nmem_strdup (NMEM mem, const char *src)
 allocates string on NMEM handle (similar strdup) More...
 
char * nmem_strdup_null (NMEM mem, const char *src)
 allocates string on NMEM handle - allows NULL ptr buffer More...
 
char * nmem_strdupn (NMEM mem, const char *src, size_t n)
 allocates string of certain size on NMEM handle More...
 
void nmem_strsplit (NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num)
 allocates sub strings out of string using certain delimitors More...
 
void nmem_strsplitx (NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num, int collapse)
 allocates sub strings out of string using certain delimitors More...
 
void nmem_strsplit_blank (NMEM nmem, const char *dstr, char ***darray, int *num)
 splits string into sub strings delimited by blanks More...
 
void nmem_strsplit_escape (NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num, int collapse, int escape_char)
 allocates sub strings out of string using certain delimitors More...
 
void nmem_strsplit_escape2 (NMEM nmem, const char *delim, const char *dstr, char ***darray, int *num, int collapse, int escape_char, int subst_escape)
 allocates sub strings out of string using certain delimitors More...
 
nmem_int_tnmem_intdup (NMEM nmem, nmem_int_t v)
 allocates and sets integer for NMEM More...
 
nmem_bool_tnmem_booldup (NMEM nmem, nmem_bool_t v)
 allocates and sets boolean for NMEM More...
 
void nmem_transfer (NMEM dst, NMEM src)
 transfers memory from one NMEM handle to another More...
 
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_malloc (NMEM n, size_t size)
 allocates memory block on NMEM handle More...
 
int nmem_get_status (char *dst, size_t l)
 returns memory status for NMEM - as XML More...
 

Detailed Description

Header for Nibble Memory functions.

This is a simple and fairly wasteful little module for nibble memory allocation. Eventually we'll put in something better.

Definition in file nmem.h.

Macro Definition Documentation

◆ NMEM_64

#define NMEM_64   1

Set to 1 if YAZ BER integer is 64-bit ; 0 otherwise.

Definition at line 48 of file nmem.h.

◆ NMEM_INT_PRINTF

#define NMEM_INT_PRINTF   "%lld"

Definition at line 60 of file nmem.h.

Typedef Documentation

◆ NMEM

typedef struct nmem_control* NMEM

NMEM handle (an opaque pointer to memory)

Definition at line 44 of file nmem.h.

◆ nmem_bool_t

typedef int nmem_bool_t

BER/utility boolean.

Definition at line 71 of file nmem.h.

◆ nmem_int_t

typedef long long int nmem_int_t

Definition at line 59 of file nmem.h.

Function Documentation

◆ nmem_booldup()

nmem_bool_t* nmem_booldup ( NMEM  nmem,
nmem_bool_t  v 
)

allocates and sets boolean for NMEM

Parameters
nmemNMEM handle
vvalue (0=false, != 0 true)
Returns
pointer to created boolean

Definition at line 48 of file nmemsdup.c.

References nmem_malloc().

Referenced by match_v_next(), and odr_booldup().

◆ 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_intdup()

nmem_int_t* nmem_intdup ( NMEM  nmem,
nmem_int_t  v 
)

allocates and sets integer for NMEM

Parameters
nmemNMEM handle
vinteger value
Returns
pointer to created integer

Definition at line 41 of file nmemsdup.c.

References nmem_malloc().

Referenced by cql_transform_parse_tok_line(), and odr_intdup().

◆ 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_strdup()

char* nmem_strdup ( NMEM  mem,
const char *  src 
)

◆ nmem_strdup_null()

char* nmem_strdup_null ( NMEM  mem,
const char *  src 
)

allocates string on NMEM handle - allows NULL ptr buffer

Parameters
memHNEM handle
srcstring
Returns
duplicated string or NULL if src was NULL

Definition at line 25 of file nmemsdup.c.

References nmem_strdup().

Referenced by gfs_server_new(), and odr_strdup_null().

◆ nmem_strdupn()

char* nmem_strdupn ( NMEM  mem,
const char *  src,
size_t  n 
)

allocates string of certain size on NMEM handle

Parameters
memNMEM handle
srcstring
nsize of string
Returns
duplicated string (0 terminated)

Definition at line 33 of file nmemsdup.c.

References nmem_malloc().

Referenced by extract_user_pass(), nmem_strsplit_escape2(), odr_strdupn(), yaz_marc_add_controlfield(), yaz_marc_add_datafield(), yaz_marc_add_leader(), yaz_marc_add_subfield(), and yaz_record_render().

◆ nmem_strsplit()

void nmem_strsplit ( NMEM  nmem,
const char *  delim,
const char *  dstr,
char ***  darray,
int *  num 
)

allocates sub strings out of string using certain delimitors

Parameters
nmemNMEM handle
delimdelimitor chars (splits on each char in there)
dstrstring to be split
darrayresult string array for each sub string
numnumber of result strings

Definition at line 61 of file nmemsdup.c.

References nmem_strsplitx().

Referenced by nmem_strsplit_blank(), xml_config_read(), yaz_pqf_parse_facet_list(), yaz_set_proposal_charneg_list(), yaz_solr_sortkeys_to_sort_spec(), and ZOOM_connection_get_databases().

◆ nmem_strsplit_blank()

void nmem_strsplit_blank ( NMEM  nmem,
const char *  dstr,
char ***  darray,
int *  num 
)

splits string into sub strings delimited by blanks

Parameters
nmemNMEM handle
dstrstring to be split
darrayresult string array for each sub string
numnumber of result strings

Definition at line 55 of file nmemsdup.c.

References nmem_strsplit().

Referenced by yaz_srw_sortkeys_to_sort_spec().

◆ nmem_strsplit_escape()

void nmem_strsplit_escape ( NMEM  nmem,
const char *  delim,
const char *  dstr,
char ***  darray,
int *  num,
int  collapse,
int  escape_char 
)

allocates sub strings out of string using certain delimitors

Parameters
nmemNMEM handle
delimdelimitor chars (splits on each char in there)
dstrstring to be split
darrayresult string array for each sub string
numnumber of result strings
collapse1=collapse multiple delims to one; 0=no collapse
escape_char!= 0, an escape char (could be )

Definition at line 73 of file nmemsdup.c.

References nmem_strsplit_escape2().

Referenced by nmem_strsplitx().

◆ nmem_strsplit_escape2()

void nmem_strsplit_escape2 ( NMEM  nmem,
const char *  delim,
const char *  dstr,
char ***  darray,
int *  num,
int  collapse,
int  escape_char,
int  subst_escape 
)

allocates sub strings out of string using certain delimitors

Parameters
nmemNMEM handle
delimdelimitor chars (splits on each char in there)
dstrstring to be split
darrayresult string array for each sub string
numnumber of result strings
collapse1=collapse multiple delims to one; 0=no collapse
escape_char!= 0, an escape char (could be )
subst_escape1=substitute escapes, 0 leave as is

Definition at line 81 of file nmemsdup.c.

References nmem_malloc(), and nmem_strdupn().

Referenced by nmem_strsplit_escape().

◆ nmem_strsplitx()

void nmem_strsplitx ( NMEM  nmem,
const char *  delim,
const char *  dstr,
char ***  darray,
int *  num,
int  collapse 
)

allocates sub strings out of string using certain delimitors

Parameters
nmemNMEM handle
delimdelimitor chars (splits on each char in there)
dstrstring to be split
darrayresult string array for each sub string
numnumber of result strings
collapse1=collapse multiple delims to one; 0=no collapse

Definition at line 67 of file nmemsdup.c.

References nmem_strsplit_escape().

Referenced by nmem_strsplit(), yaz_solr_sortkeys_to_sort_spec(), and yaz_srw_sortkeys_to_sort_spec().

◆ 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().