2 * Copyright (C) 1995-2006, Index Data ApS
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation, in whole or in part, for any purpose, is hereby granted,
8 * 1. This copyright and permission notice appear in all copies of the
9 * software and its documentation. Notices of copyright or attribution
10 * which appear at the beginning of any file must remain unchanged.
12 * 2. The names of Index Data or the individual authors may not be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
20 * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
22 * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 * $Id: nmem.h,v 1.20 2006-08-11 12:50:23 adam Exp $
31 * \brief Header for Nibble Memory functions
33 * This is a simple and fairly wasteful little module for nibble memory
34 * allocation. Evemtually we'll put in something better.
40 #include <yaz/yconfig.h>
43 #include <libxml/parser.h>
54 /** \brief NMEM/YAZ MUTEX opaque pointer */
55 typedef struct nmem_mutex *NMEM_MUTEX;
56 /** \brief create Mutex */
57 YAZ_EXPORT void nmem_mutex_create(NMEM_MUTEX *);
58 /** \brief enter critical section / AKA lock */
59 YAZ_EXPORT void nmem_mutex_enter(NMEM_MUTEX);
60 /** \brief leave critical section / AKA unlock */
61 YAZ_EXPORT void nmem_mutex_leave(NMEM_MUTEX);
62 /** \brief destroy MUTEX */
63 YAZ_EXPORT void nmem_mutex_destroy(NMEM_MUTEX *);
65 /** \brief NMEM handle (an opaque pointer to memory) */
66 typedef struct nmem_control *NMEM;
68 /** \brief release all memory associaged with an NMEM handle */
69 YAZ_EXPORT void nmem_reset(NMEM n);
70 /** \brief returns size in bytes of memory for NMEM handle */
71 YAZ_EXPORT int nmem_total(NMEM n);
73 /** \brief allocates string on NMEM handle (similar strdup) */
74 YAZ_EXPORT char *nmem_strdup (NMEM mem, const char *src);
75 /** \brief allocates string on NMEM handle - allows NULL ptr buffer */
76 YAZ_EXPORT char *nmem_strdup_null (NMEM mem, const char *src);
77 /** \brief allocates string of certain size on NMEM handle */
78 YAZ_EXPORT char *nmem_strdupn (NMEM mem, const char *src, size_t n);
80 /** \brief allocates sub strings out of string using certain delimitors
81 \param nmem NMEM handle
82 \param delim delimitor chars (splits on each char in there)
83 \param dstr string to be split
84 \param darray result string array for each sub string
85 \param num number of result strings
87 YAZ_EXPORT void nmem_strsplit(NMEM nmem, const char *delim,
89 char ***darray, int *num);
91 /** \brief splits string into sub strings delimited by blanks
92 \param nmem NMEM handle
93 \param dstr string to be split
94 \param darray result string array for each sub string
95 \param num number of result strings
97 YAZ_EXPORT void nmem_strsplit_blank(NMEM nmem, const char *dstr,
98 char ***darray, int *num);
100 /** \brief copies TEXT Libxml2 node data to NMEM */
101 YAZ_EXPORT char *nmem_text_node_cdata(const xmlNode *ptr, NMEM nmem);
103 /** \brief creates and allocates integer for NMEM */
104 YAZ_EXPORT int *nmem_intdup (NMEM mem, int v);
106 /** \brief transfers memory from one NMEM handle to another */
107 YAZ_EXPORT void nmem_transfer (NMEM dst, NMEM src);
109 /** \brief internal (do not use) */
110 YAZ_EXPORT void nmem_critical_enter (void);
111 /** \brief internal (do not use) */
112 YAZ_EXPORT void nmem_critical_leave (void);
116 YAZ_EXPORT NMEM nmem_create_f(const char *file, int line);
117 YAZ_EXPORT void nmem_destroy_f(const char *file, int line, NMEM n);
118 YAZ_EXPORT void *nmem_malloc_f(const char *file, int line, NMEM n, int size);
119 #define nmem_create() nmem_create_f(__FILE__, __LINE__)
120 #define nmem_destroy(x) nmem_destroy_f(__FILE__, __LINE__, (x))
121 #define nmem_malloc(x, y) nmem_malloc_f(__FILE__, __LINE__, (x), (y))
123 YAZ_EXPORT void nmem_print_list (void);
124 YAZ_EXPORT void nmem_print_list_l (int level);
128 /** \brief returns new NMEM handle */
129 YAZ_EXPORT NMEM nmem_create(void);
131 /** \brief destroys NMEM handle and memory associated with it */
132 YAZ_EXPORT void nmem_destroy(NMEM n);
134 /** \brief allocate memory block on NMEM handle */
135 YAZ_EXPORT void *nmem_malloc(NMEM n, int size);
137 #define nmem_print_list()
141 /** \brief initializes NMEM system
142 This function increments a usage counter for NMEM.. Only
143 on first usage the system is initialized.. The \fn nmem_exit
144 decrements the counter. So these must be called in pairs
146 YAZ_EXPORT void nmem_init (void);
148 /** \brief destroys NMEM system */
149 YAZ_EXPORT void nmem_exit (void);
151 YAZ_EXPORT int yaz_errno (void);
152 YAZ_EXPORT void yaz_set_errno (int v);
153 YAZ_EXPORT void yaz_strerror(char *buf, int max);
155 /** \brief returns memory in use (by application)
156 \param p pointer to size (in bytes)
158 YAZ_EXPORT void nmem_get_memory_in_use(size_t *p);
159 /** \brief returns memory in free (for later reuse)
161 YAZ_EXPORT void nmem_get_memory_free(size_t *p);
169 * indent-tabs-mode: nil
171 * vim: shiftwidth=4 tabstop=8 expandtab