NCBI C++ ToolKit
ncbimem.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef _NCBIMEM_
2 #define _NCBIMEM_
3 
4 /* $Id: ncbimem.hpp 80115 2017-11-08 12:52:45Z ivanov $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * File Name: ncbimem.h
30 *
31 * Author: Gish, Kans, Ostell, Schuler
32 *
33 * Version Creation Date: 1/1/91
34 *
35 * C Tolkit Revision: 6.12
36 *
37 * File Description:
38 * prototypes for ncbi memory functions
39 *
40 * ==========================================================================
41 */
42 
43 #include <corelib/ncbistd.hpp>
45 
46 /** @addtogroup CToolsBridge
47  *
48  * @{
49  */
50 
52 
53 
54 NLM_EXTERN void* LIBCALL Nlm_MemNew(size_t size);
55 NLM_EXTERN void* LIBCALL Nlm_MemGet(size_t size, unsigned int flags);
56 NLM_EXTERN void* LIBCALL Nlm_MemMore(void* ptr, size_t size);
57 NLM_EXTERN void* LIBCALL Nlm_MemExtend(void* ptr, size_t size, size_t oldsize);
58 NLM_EXTERN void* LIBCALL Nlm_MemFree(void* ptr);
59 NLM_EXTERN void* LIBCALL Nlm_MemCopy(void* dst, const void* src, size_t bytes);
60 NLM_EXTERN void* LIBCALL Nlm_MemMove(void* dst, const void* src, size_t bytes);
61 NLM_EXTERN void* LIBCALL Nlm_MemFill(void* ptr, int value, size_t bytes);
62 NLM_EXTERN void* LIBCALL Nlm_MemDup(const void* orig, size_t size);
63 NLM_EXTERN size_t LIBCALL Nlm_MemSearch(const void* where, size_t where_size,
64  const void* what, size_t what_size);
65 
66 #if 0
67 #if defined(OS_MAC) || defined(OS_UNIX_DARWIN) || defined(OS_MSWIN) || defined(MSC_VIRT)
74 #endif
75 #endif /*0*/
76 
77 
78 
79 /* [UNIX only] set the limit for the heap size and its increase policy for
80  * NCBI memory allocation functions:
81  * MemGet, MemNew, MemMore, MemExtend
82  * when the heap size reaches "curr", it ussues a warning, then it increases
83  * "curr" by "add" bytes -- unless "curr" has already reached "max".
84  * in the latter case, program ussues a FATAL_ERROR error message and
85  * the NCBI allocation function returns NULL
86  * NOTE: specifying "curr" == 0 switch off the heap restriction algorithm;
87  * and it is off by default(if Nlm_SetHeapLimit has not been called)
88  */
89 NLM_EXTERN Nlm_Boolean Nlm_SetHeapLimit(size_t curr, size_t add, size_t max);
90 
91 
92 /* Do Nlm_Calloc by {Nlm_Malloc + Nlm_MemSet} rather than native {calloc}
93  */
94 NLM_EXTERN void* Nlm_CallocViaMalloc(size_t n_elem, size_t item_size);
95 
96 
97 
98 /* ========= MACROS ======== */
99 
100 
101 /* low-level ANSI-style functions */
102 #define Nlm_Malloc malloc
103 #define Nlm_Calloc calloc
104 #define Nlm_Realloc realloc
105 #define Nlm_Free free
106 #define Nlm_MemSet memset
107 #define Nlm_MemCpy memcpy
108 #define Nlm_MemChr memchr
109 #define Nlm_MemCmp memcmp
110 
111 
112 #ifdef OS_UNIX_SOL
113 /* Kludge for Solaris("calloc()" sometimes fails in MT aplications) */
114 #undef Nlm_Calloc
115 #define Nlm_Calloc Nlm_CallocViaMalloc
116 #endif
117 
118 
119 #define Malloc Nlm_Malloc
120 #define Calloc Nlm_Calloc
121 #define Realloc Nlm_Realloc
122 #define Free Nlm_Free
123 #define MemSet Nlm_MemSet
124 #define MemCpy Nlm_MemCpy
125 #define MemChr Nlm_MemChr
126 #define MemCmp Nlm_MemCmp
127 #define MemSearch Nlm_MemSearch
128 
129 /*** High-level NCBI functions ***/
130 
131 /* Fake handle functions with pointer functions */
132 
133 #if !(defined(OS_MAC) || defined(OS_UNIX_DARWIN) || defined(OS_MSWIN) || defined(MSC_VIRT) )
134 #define Nlm_HandNew(a) Nlm_MemNew(a)
135 #define Nlm_HandGet(a,b) Nlm_MemGet(a,b)
136 #define Nlm_HandMore(a,b) Nlm_MemMore(a,b)
137 #define Nlm_HandFree(a) Nlm_MemFree(a)
138 #define Nlm_HandLock(a) (a)
139 #define Nlm_HandUnlock(a) NULL
140 #endif
141 
142 /* Pointer functions */
143 #define MemNew(x) Nlm_MemGet(x,MGET_CLEAR|MGET_ERRPOST)
144 #define MemGet(x,y) Nlm_MemGet(x,(unsigned int)(y))
145 #define MemFree Nlm_MemFree
146 #define MemMore Nlm_MemMore
147 #define MemExtend Nlm_MemExtend
148 #define MemCopy Nlm_MemCopy
149 #define MemMove Nlm_MemMove
150 #define MemFill Nlm_MemFill
151 #define MemDup Nlm_MemDup
152 
153 #define HandNew Nlm_HandNew
154 #define HandGet Nlm_HandGet
155 #define HandMore Nlm_HandMore
156 #define HandFree Nlm_HandFree
157 #define HandLock Nlm_HandLock
158 #define HandUnlock Nlm_HandUnlock
159 
160 #if (defined(OS_UNIX_SYSV) || defined(OS_UNIX_SUN) || defined(OS_UNIX_OSF1) || defined(OS_UNIX_LINUX) || defined(OS_UNIX_AIX) || defined(OS_UNIX_DARWIN)) && !defined(OS_UNIX_ULTRIX) || defined(OS_UNIX_FREEBSD)
161 #ifndef IBM_DISABLE_MMAP
162 #define MMAP_AVAIL
163 #endif
164 #endif
165 
166 
167 
168 #if defined(_DEBUG) && defined(OS_MSWIN)
169 NLM_EXTERN void* LIBCALL Nlm_MemFreeTrace (void* , const char*, const char*, int);
170 #undef MemFree
171 #define MemFree(_ptr_) Nlm_MemFreeTrace(_ptr_,THIS_MODULE,THIS_FILE,__LINE__)
172 #endif
173 
174 
175 #ifdef _WINDLL
176 NLM_EXTERN void* dll_Malloc(size_t bytes);
177 NLM_EXTERN void dll_Free (void* pMem);
178 #else
179 #define dll_Malloc(x) (void*) Nlm_Malloc(x)
180 #define dll_Free(x) Nlm_Free((void*) (x))
181 #endif
182 
183 
184 /* flags for MemGet */
185 #define MGET_CLEAR 0x0001
186 #define MGET_ERRPOST 0x0004
187 
188 
189 /* obsolete */
190 #define MG_CLEAR MGET_CLEAR
191 #define MG_MAXALLOC 0x0002
192 #define MG_ERRPOST MGET_ERRPOST
193 
194 
195 
196 /****************************************************************************
197  * Memory mapping
198  */
199 
200 /* This structure is allocated and filled by Nlm_MemMapInit.
201  The Nlm_Handle's are used by WIN32, "file_size" is used by
202  UNIX memory mapping when the the files are unmapped. */
203 typedef struct _nlm_mem_map
204 {
205 #ifdef WIN32
206  Nlm_Handle hMap;
207 #endif
211 
212 /* Determine if memory-mapping is supported by the NCBI toolkit
213  */
215 
216 
217 /* Initializes the memory mapping on file "name"
218  * Return NULL on error
219  * NOTE: return non-NULL zero-filled structure if the file has zero length
220  */
222 
223 
224 /* Close the memory mapping
225  */
227 
228 
229 /* Advises the VM system that the a certain region of user mapped memory
230  will be accessed following a type of pattern. The VM system uses this
231  information to optimize work wih mapped memory.
232  */
233 typedef enum {
234  eMMA_Normal, /* No further special threatment */
235  eMMA_Random, /* Expect random page references */
236  eMMA_Sequential, /* Expect sequential page references */
237  eMMA_WillNeed, /* Will need these pages */
238  eMMA_DontNeed /* Don't need these pages */
240 
241 Nlm_Boolean Nlm_MemMapAdvise(void* addr, size_t len, EMemMapAdvise advise);
243 
244 
246 
247 /* @} */
248 
249 #endif /* _NCBIMEM_ */
char value[7]
Definition: config.c:431
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
EMemMapAdvise
Definition: ncbimem.hpp:233
#define BEGIN_CTRANSITION_SCOPE
Definition: ncbilcl.hpp:49
NLM_EXTERN void Nlm_MemMapFini(Nlm_MemMapPtr mem_mapp)
Definition: ct_ncbimem.cpp:812
NLM_EXTERN void *LIBCALL Nlm_MemCopy(void *dst, const void *src, size_t bytes)
Definition: ct_ncbimem.cpp:330
#define PNTR
Definition: ncbistd.hpp:98
void * Nlm_Handle
Definition: ncbistd.hpp:118
unsigned char Nlm_Boolean
Definition: ncbistd.hpp:135
#define Nlm_HandUnlock(a)
Definition: ncbimem.hpp:139
NLM_EXTERN Nlm_Boolean Nlm_SetHeapLimit(size_t curr, size_t add, size_t max)
Definition: ct_ncbimem.cpp:139
char * Nlm_CharPtr
Definition: ncbistd.hpp:123
#define Nlm_HandLock(a)
Definition: ncbimem.hpp:138
NLM_EXTERN Nlm_MemMapPtr Nlm_MemMapInit(const Nlm_Char PNTR name)
Definition: ct_ncbimem.cpp:742
#define Nlm_HandGet(a, b)
Definition: ncbimem.hpp:135
NLM_EXTERN void *LIBCALL Nlm_MemFree(void *ptr)
Definition: ct_ncbimem.cpp:298
NLM_EXTERN void *LIBCALL Nlm_MemFill(void *ptr, int value, size_t bytes)
Definition: ct_ncbimem.cpp:391
#define dll_Malloc(x)
Definition: ncbimem.hpp:179
#define Nlm_HandMore(a, b)
Definition: ncbimem.hpp:136
BEGIN_CTRANSITION_SCOPE NLM_EXTERN void *LIBCALL Nlm_MemNew(size_t size)
Definition: ct_ncbimem.cpp:271
NLM_EXTERN size_t LIBCALL Nlm_MemSearch(const void *where, size_t where_size, const void *what, size_t what_size)
Definition: ct_ncbimem.cpp:404
#define Nlm_Int8
Definition: ncbiopt.hpp:231
struct _nlm_mem_map Nlm_MemMapPtr
NLM_EXTERN Nlm_Boolean Nlm_MemMapAvailable(void)
Definition: ct_ncbimem.cpp:732
NLM_EXTERN void *LIBCALL Nlm_MemExtend(void *ptr, size_t size, size_t oldsize)
Definition: ct_ncbimem.cpp:281
NLM_EXTERN void * Nlm_CallocViaMalloc(size_t n_elem, size_t item_size)
Definition: ct_ncbimem.cpp:94
char Nlm_Char
Definition: ncbistd.hpp:123
#define LIBCALL
Definition: ncbistd.hpp:297
NLM_EXTERN void *LIBCALL Nlm_MemGet(size_t size, unsigned int flags)
Definition: ct_ncbimem.cpp:266
Nlm_Boolean Nlm_MemMapAdvisePtr(Nlm_MemMapPtr ptr, EMemMapAdvise advise)
Definition: ct_ncbimem.cpp:856
NLM_EXTERN void *LIBCALL Nlm_MemMove(void *dst, const void *src, size_t bytes)
Definition: ct_ncbimem.cpp:365
#define Nlm_HandNew(a)
Definition: ncbimem.hpp:134
Nlm_Int8 file_size
Definition: ncbimem.hpp:208
Nlm_CharPtr mmp_begin
Definition: ncbimem.hpp:209
Nlm_Boolean Nlm_MemMapAdvise(void *addr, size_t len, EMemMapAdvise advise)
Definition: ct_ncbimem.cpp:829
#define Nlm_HandFree(a)
Definition: ncbimem.hpp:137
NLM_EXTERN void *LIBCALL Nlm_MemDup(const void *orig, size_t size)
Definition: ct_ncbimem.cpp:342
#define END_CTRANSITION_SCOPE
Definition: ncbilcl.hpp:50
#define NLM_EXTERN
Definition: ncbistd.hpp:290
struct _nlm_mem_map Nlm_MemMap
#define dll_Free(x)
Definition: ncbimem.hpp:180
NLM_EXTERN void *LIBCALL Nlm_MemMore(void *ptr, size_t size)
Definition: ct_ncbimem.cpp:276
@ eMMA_WillNeed
Definition: ncbimem.hpp:237
@ eMMA_Random
Definition: ncbimem.hpp:235
@ eMMA_DontNeed
Definition: ncbimem.hpp:238
@ eMMA_Normal
Definition: ncbimem.hpp:234
@ eMMA_Sequential
Definition: ncbimem.hpp:236
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is orig
int len
const struct ncbi::grid::netcache::search::fields::SIZE size
T max(T x_, T y_)
Modified on Wed Feb 28 07:12:00 2024 by modify_doxy.py rev. 669887