Scippy

SCIP

Solving Constraint Integer Programs

scip_mem.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_mem.h
17  * @ingroup PUBLICCOREAPI
18  * @brief public methods for memory management
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Thorsten Koch
22  * @author Alexander Martin
23  * @author Marc Pfetsch
24  * @author Kati Wolter
25  * @author Gregor Hendel
26  * @author Leona Gottwald
27  */
28 
29 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
30 
31 #ifndef __SCIP_SCIP_MEM_H__
32 #define __SCIP_SCIP_MEM_H__
33 
34 
35 #include "blockmemshell/memory.h"
36 #include "scip/def.h"
37 #include "scip/type_retcode.h"
38 #include "scip/type_scip.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /**@addtogroup PublicMemoryMethods
45  *
46  * @{
47  */
48 
49 /* Standard Memory Management Macros */
50 
51 #define SCIPallocMemory(scip,ptr) ( (BMSallocMemory((ptr)) == NULL) \
52  ? SCIP_NOMEMORY : SCIP_OKAY )
53 #define SCIPallocClearMemory(scip,ptr) ( (BMSallocClearMemory((ptr)) == NULL) \
54  ? SCIP_NOMEMORY : SCIP_OKAY )
55 #define SCIPallocMemoryArray(scip,ptr,num) ( (BMSallocMemoryArray((ptr), (num)) == NULL) \
56  ? SCIP_NOMEMORY : SCIP_OKAY )
57 #define SCIPallocClearMemoryArray(scip,ptr,num) ( (BMSallocClearMemoryArray((ptr), (num)) == NULL) \
58  ? SCIP_NOMEMORY : SCIP_OKAY )
59 #define SCIPallocMemorySize(scip,ptr,size) ( (BMSallocMemorySize((ptr), (size)) == NULL) \
60  ? SCIP_NOMEMORY : SCIP_OKAY )
61 #define SCIPreallocMemoryArray(scip,ptr,newnum) ( (BMSreallocMemoryArray((ptr), (newnum)) == NULL) \
62  ? SCIP_NOMEMORY : SCIP_OKAY )
63 #define SCIPreallocMemorySize(scip,ptr,newsize) ( (BMSreallocMemorySize((ptr), (newsize)) == NULL) \
64  ? SCIP_NOMEMORY : SCIP_OKAY )
65 #define SCIPduplicateMemory(scip, ptr, source) ( (BMSduplicateMemory((ptr), (source)) == NULL) \
66  ? SCIP_NOMEMORY : SCIP_OKAY )
67 #define SCIPduplicateMemoryArray(scip, ptr, source, num) ( (BMSduplicateMemoryArray((ptr), (source), (num)) == NULL) \
68  ? SCIP_NOMEMORY : SCIP_OKAY )
69 #define SCIPfreeMemory(scip,ptr) BMSfreeMemory(ptr)
70 #define SCIPfreeMemoryNull(scip,ptr) BMSfreeMemoryNull(ptr)
71 #define SCIPfreeMemoryArray(scip,ptr) BMSfreeMemoryArray(ptr)
72 #define SCIPfreeMemoryArrayNull(scip,ptr) BMSfreeMemoryArrayNull(ptr)
73 #define SCIPfreeMemorySize(scip,ptr) BMSfreeMemorySize(ptr)
74 #define SCIPfreeMemorySizeNull(scip,ptr) BMSfreeMemorySizeNull(ptr)
75 
76 /* Block Memory Management Macros
77  *
78  */
79 
80 #define SCIPallocBlockMemory(scip,ptr) ( (BMSallocBlockMemory(SCIPblkmem(scip), (ptr)) == NULL) \
81  ? SCIP_NOMEMORY : SCIP_OKAY )
82 #define SCIPallocClearBlockMemory(scip,ptr) ( (BMSallocClearBlockMemory(SCIPblkmem(scip), (ptr)) == NULL) \
83  ? SCIP_NOMEMORY : SCIP_OKAY )
84 #define SCIPallocBlockMemoryArray(scip,ptr,num) ( (BMSallocBlockMemoryArray(SCIPblkmem(scip), (ptr), (num)) == NULL) \
85  ? SCIP_NOMEMORY : SCIP_OKAY )
86 #define SCIPallocBlockMemorySize(scip,ptr,size) ( (BMSallocBlockMemorySize(SCIPblkmem(scip), (ptr), (size)) == NULL) \
87  ? SCIP_NOMEMORY : SCIP_OKAY )
88 #define SCIPallocClearBlockMemoryArray(scip,ptr,num) ( (BMSallocClearBlockMemoryArray(SCIPblkmem(scip), (ptr), (num)) == NULL) \
89  ? SCIP_NOMEMORY : SCIP_OKAY )
90 #define SCIPreallocBlockMemoryArray(scip,ptr,oldnum,newnum) ( (BMSreallocBlockMemoryArray(SCIPblkmem(scip), (ptr), (oldnum), (newnum)) == NULL) \
91  ? SCIP_NOMEMORY : SCIP_OKAY )
92 #define SCIPreallocBlockMemorySize(scip,ptr,oldsize,newsize) ( (BMSreallocBlockMemorySize(SCIPblkmem(scip), (ptr), (oldsize), (newsize)) == NULL) \
93  ? SCIP_NOMEMORY : SCIP_OKAY )
94 #define SCIPduplicateBlockMemory(scip, ptr, source) ( (BMSduplicateBlockMemory(SCIPblkmem(scip), (ptr), (source)) == NULL) \
95  ? SCIP_NOMEMORY : SCIP_OKAY )
96 #define SCIPduplicateBlockMemoryArray(scip, ptr, source, num) ( (BMSduplicateBlockMemoryArray(SCIPblkmem(scip), (ptr), (source), (num)) == NULL) \
97  ? SCIP_NOMEMORY : SCIP_OKAY )
98 #define SCIPensureBlockMemoryArray(scip,ptr,arraysizeptr,minsize) ( (SCIPensureBlockMemoryArray_call((scip), (void**)(ptr), sizeof(**(ptr)), (arraysizeptr), (minsize))) )
99 #define SCIPfreeBlockMemory(scip,ptr) BMSfreeBlockMemory(SCIPblkmem(scip), (ptr))
100 #define SCIPfreeBlockMemoryNull(scip,ptr) BMSfreeBlockMemoryNull(SCIPblkmem(scip), (ptr))
101 #define SCIPfreeBlockMemoryArray(scip,ptr,num) BMSfreeBlockMemoryArray(SCIPblkmem(scip), (ptr), (num))
102 #define SCIPfreeBlockMemoryArrayNull(scip,ptr,num) BMSfreeBlockMemoryArrayNull(SCIPblkmem(scip), (ptr), (num))
103 #define SCIPfreeBlockMemorySize(scip,ptr,size) BMSfreeBlockMemorySize(SCIPblkmem(scip), (ptr), (size))
104 #define SCIPfreeBlockMemorySizeNull(scip,ptr,size) BMSfreeBlockMemorySizeNull(SCIPblkmem(scip), (ptr), (size))
105 
106 
107 /* Buffer Memory Management Macros
108  *
109  *
110  */
111 
112 
113 #define SCIPallocBuffer(scip,ptr) ( (BMSallocBufferMemory(SCIPbuffer(scip), (ptr)) == NULL) \
114  ? SCIP_NOMEMORY : SCIP_OKAY )
115 #define SCIPallocBufferArray(scip,ptr,num) ( (BMSallocBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
116  ? SCIP_NOMEMORY : SCIP_OKAY )
117 #define SCIPallocClearBufferArray(scip,ptr,num) ( (BMSallocClearBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
118  ? SCIP_NOMEMORY : SCIP_OKAY )
119 #define SCIPreallocBufferArray(scip,ptr,num) ( (BMSreallocBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
120  ? SCIP_NOMEMORY : SCIP_OKAY )
121 #define SCIPduplicateBuffer(scip,ptr,source) ( (BMSduplicateBufferMemory(SCIPbuffer(scip), (ptr), (source), (size_t)sizeof(**(ptr))) \
122  ? SCIP_NOMEMORY : SCIP_OKAY )
123 #define SCIPduplicateBufferArray(scip,ptr,source,num) ( (BMSduplicateBufferMemoryArray(SCIPbuffer(scip), (ptr), (source), (num)) == NULL) \
124  ? SCIP_NOMEMORY : SCIP_OKAY )
125 #define SCIPfreeBuffer(scip,ptr) BMSfreeBufferMemorySize(SCIPbuffer(scip), (ptr))
126 #define SCIPfreeBufferNull(scip,ptr) BMSfreeBufferMemoryNull(SCIPbuffer(scip), (ptr))
127 #define SCIPfreeBufferArray(scip,ptr) BMSfreeBufferMemoryArray(SCIPbuffer(scip), (ptr))
128 #define SCIPfreeBufferArrayNull(scip,ptr) BMSfreeBufferMemoryArrayNull(SCIPbuffer(scip), (ptr))
129 
130 
131 #define SCIPallocCleanBuffer(scip,ptr) ( (BMSallocBufferMemory(SCIPcleanbuffer(scip), (ptr)) == NULL) \
132  ? SCIP_NOMEMORY : SCIP_OKAY )
133 #define SCIPallocCleanBufferArray(scip,ptr,num) ( (BMSallocBufferMemoryArray(SCIPcleanbuffer(scip), (ptr), (num)) == NULL) \
134  ? SCIP_NOMEMORY : SCIP_OKAY )
135 #define SCIPfreeCleanBuffer(scip,ptr) BMSfreeBufferMemorySize(SCIPcleanbuffer(scip), (ptr))
136 #define SCIPfreeCleanBufferNull(scip,ptr) BMSfreeBufferMemoryNull(SCIPcleanbuffer(scip), (ptr))
137 #define SCIPfreeCleanBufferArray(scip,ptr) BMSfreeBufferMemoryArray(SCIPcleanbuffer(scip), (ptr))
138 #define SCIPfreeCleanBufferArrayNull(scip,ptr) BMSfreeBufferMemoryArrayNull(SCIPcleanbuffer(scip), (ptr))
139 
140 
141 /* Memory Management Functions
142  *
143  *
144  */
145 
146 /** returns block memory to use at the current time
147  *
148  * @return the block memory to use at the current time.
149  */
150 SCIP_EXPORT
152  SCIP* scip /**< SCIP data structure */
153  );
154 
155 /** returns buffer memory for short living temporary objects
156  *
157  * @return the buffer memory for short living temporary objects
158  */
159 SCIP_EXPORT
161  SCIP* scip /**< SCIP data structure */
162  );
163 
164 /** returns clean buffer memory for short living temporary objects initialized to all zero
165  *
166  * @return the buffer memory for short living temporary objects initialized to all zero
167  */
168 SCIP_EXPORT
170  SCIP* scip /**< SCIP data structure */
171  );
172 
173 /** returns the total number of bytes used in block and buffer memory
174  *
175  * @return the total number of bytes used in block and buffer memory.
176  */
177 SCIP_EXPORT
179  SCIP* scip /**< SCIP data structure */
180  );
181 
182 /** returns the total number of bytes in block and buffer memory
183  *
184  * @return the total number of bytes in block and buffer memory.
185  */
186 SCIP_EXPORT
188  SCIP* scip /**< SCIP data structure */
189  );
190 
191 /** returns the estimated number of bytes used by external software, e.g., the LP solver
192  *
193  * @return the estimated number of bytes used by external software, e.g., the LP solver.
194  */
195 SCIP_EXPORT
197  SCIP* scip /**< SCIP data structure */
198  );
199 
200 /** calculate memory size for dynamically allocated arrays
201  *
202  * @return the memory size for dynamically allocated arrays.
203  */
204 SCIP_EXPORT
206  SCIP* scip, /**< SCIP data structure */
207  int num /**< minimum number of entries to store */
208  );
209 
210 /** extends a dynamically allocated block memory array to be able to store at least the given number of elements;
211  * use SCIPensureBlockMemoryArray() define to call this method!
212  *
213  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
214  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
215  */
216 SCIP_EXPORT
218  SCIP* scip, /**< SCIP data structure */
219  void** arrayptr, /**< pointer to dynamically sized array */
220  size_t elemsize, /**< size in bytes of each element in array */
221  int* arraysize, /**< pointer to current array size */
222  int minsize /**< required minimal array size */
223  );
224 
225 /** prints output about used memory */
226 SCIP_EXPORT
228  SCIP* scip /**< SCIP data structure */
229  );
230 
231 /** @} */
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #endif
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:130
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
type definitions for return codes for SCIP methods
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
SCIP_RETCODE SCIPensureBlockMemoryArray_call(SCIP *scip, void **arrayptr, size_t elemsize, int *arraysize, int minsize)
Definition: scip_mem.c:146
void SCIPprintMemoryDiagnostic(SCIP *scip)
Definition: scip_mem.c:172
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip_mem.c:63
type definitions for SCIP&#39;s main datastructure
BMS_BUFMEM * SCIPcleanbuffer(SCIP *scip)
Definition: scip_mem.c:77
SCIP_Longint SCIPgetMemTotal(SCIP *scip)
Definition: scip_mem.c:104
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:91
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:117
#define SCIP_Longint
Definition: def.h:162
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:430
memory allocation routines