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-2018 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 scip.zib.de. */
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 Robert Lion 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 /* In debug mode, we include the SCIP's structure in scip.c, such that no one can access
41  * this structure except the interface methods in scip.c.
42  * In optimized mode, the structure is included in scip.h, because some of the methods
43  * are implemented as defines for performance reasons (e.g. the numerical comparisons).
44  * Additionally, the internal "set.h" is included, such that the defines in set.h are
45  * available in optimized mode.
46  */
47 #ifdef NDEBUG
48 #include "scip/struct_scip.h"
49 #include "scip/struct_stat.h"
50 #include "scip/set.h"
51 #include "scip/tree.h"
52 #include "scip/misc.h"
53 #include "scip/var.h"
54 #include "scip/cons.h"
55 #include "scip/solve.h"
56 #include "scip/debug.h"
57 #endif
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /**@addtogroup PublicMemoryMethods
64  *
65  * @{
66  */
67 
68 /* Standard Memory Management Macros */
69 
70 #define SCIPallocMemory(scip,ptr) ( (BMSallocMemory((ptr)) == NULL) \
71  ? SCIP_NOMEMORY : SCIP_OKAY )
72 #define SCIPallocMemoryArray(scip,ptr,num) ( (BMSallocMemoryArray((ptr), (num)) == NULL) \
73  ? SCIP_NOMEMORY : SCIP_OKAY )
74 #define SCIPallocClearMemoryArray(scip,ptr,num) ( (BMSallocClearMemoryArray((ptr), (num)) == NULL) \
75  ? SCIP_NOMEMORY : SCIP_OKAY )
76 #define SCIPallocMemorySize(scip,ptr,size) ( (BMSallocMemorySize((ptr), (size)) == NULL) \
77  ? SCIP_NOMEMORY : SCIP_OKAY )
78 #define SCIPreallocMemoryArray(scip,ptr,newnum) ( (BMSreallocMemoryArray((ptr), (newnum)) == NULL) \
79  ? SCIP_NOMEMORY : SCIP_OKAY )
80 #define SCIPreallocMemorySize(scip,ptr,newsize) ( (BMSreallocMemorySize((ptr), (newsize)) == NULL) \
81  ? SCIP_NOMEMORY : SCIP_OKAY )
82 #define SCIPduplicateMemory(scip, ptr, source) ( (BMSduplicateMemory((ptr), (source)) == NULL) \
83  ? SCIP_NOMEMORY : SCIP_OKAY )
84 #define SCIPduplicateMemoryArray(scip, ptr, source, num) ( (BMSduplicateMemoryArray((ptr), (source), (num)) == NULL) \
85  ? SCIP_NOMEMORY : SCIP_OKAY )
86 #define SCIPfreeMemory(scip,ptr) BMSfreeMemory(ptr)
87 #define SCIPfreeMemoryNull(scip,ptr) BMSfreeMemoryNull(ptr)
88 #define SCIPfreeMemoryArray(scip,ptr) BMSfreeMemoryArray(ptr)
89 #define SCIPfreeMemoryArrayNull(scip,ptr) BMSfreeMemoryArrayNull(ptr)
90 #define SCIPfreeMemorySize(scip,ptr) BMSfreeMemorySize(ptr)
91 #define SCIPfreeMemorySizeNull(scip,ptr) BMSfreeMemorySizeNull(ptr)
92 
93 /* Block Memory Management Macros
94  *
95  */
96 
97 #define SCIPallocBlockMemory(scip,ptr) ( (BMSallocBlockMemory(SCIPblkmem(scip), (ptr)) == NULL) \
98  ? SCIP_NOMEMORY : SCIP_OKAY )
99 #define SCIPallocBlockMemoryArray(scip,ptr,num) ( (BMSallocBlockMemoryArray(SCIPblkmem(scip), (ptr), (num)) == NULL) \
100  ? SCIP_NOMEMORY : SCIP_OKAY )
101 #define SCIPallocBlockMemorySize(scip,ptr,size) ( (BMSallocBlockMemorySize(SCIPblkmem(scip), (ptr), (size)) == NULL) \
102  ? SCIP_NOMEMORY : SCIP_OKAY )
103 #define SCIPallocClearBlockMemoryArray(scip,ptr,num) ( (BMSallocClearBlockMemoryArray(SCIPblkmem(scip), (ptr), (num)) == NULL) \
104  ? SCIP_NOMEMORY : SCIP_OKAY )
105 #define SCIPreallocBlockMemoryArray(scip,ptr,oldnum,newnum) ( (BMSreallocBlockMemoryArray(SCIPblkmem(scip), (ptr), (oldnum), (newnum)) == NULL) \
106  ? SCIP_NOMEMORY : SCIP_OKAY )
107 #define SCIPreallocBlockMemorySize(scip,ptr,oldsize,newsize) ( (BMSreallocBlockMemorySize(SCIPblkmem(scip), (ptr), (oldsize), (newsize)) == NULL) \
108  ? SCIP_NOMEMORY : SCIP_OKAY )
109 #define SCIPduplicateBlockMemory(scip, ptr, source) ( (BMSduplicateBlockMemory(SCIPblkmem(scip), (ptr), (source)) == NULL) \
110  ? SCIP_NOMEMORY : SCIP_OKAY )
111 #define SCIPduplicateBlockMemoryArray(scip, ptr, source, num) ( (BMSduplicateBlockMemoryArray(SCIPblkmem(scip), (ptr), (source), (num)) == NULL) \
112  ? SCIP_NOMEMORY : SCIP_OKAY )
113 #define SCIPensureBlockMemoryArray(scip,ptr,arraysizeptr,minsize) ( (SCIPensureBlockMemoryArray_call((scip), (void**)(ptr), sizeof(**(ptr)), (arraysizeptr), (minsize))) )
114 #define SCIPfreeBlockMemory(scip,ptr) BMSfreeBlockMemory(SCIPblkmem(scip), (ptr))
115 #define SCIPfreeBlockMemoryNull(scip,ptr) BMSfreeBlockMemoryNull(SCIPblkmem(scip), (ptr))
116 #define SCIPfreeBlockMemoryArray(scip,ptr,num) BMSfreeBlockMemoryArray(SCIPblkmem(scip), (ptr), (num))
117 #define SCIPfreeBlockMemoryArrayNull(scip,ptr,num) BMSfreeBlockMemoryArrayNull(SCIPblkmem(scip), (ptr), (num))
118 #define SCIPfreeBlockMemorySize(scip,ptr,size) BMSfreeBlockMemorySize(SCIPblkmem(scip), (ptr), (size))
119 #define SCIPfreeBlockMemorySizeNull(scip,ptr,size) BMSfreeBlockMemorySizeNull(SCIPblkmem(scip), (ptr), (size))
120 
121 
122 /* Buffer Memory Management Macros
123  *
124  *
125  */
126 
127 
128 #define SCIPallocBuffer(scip,ptr) ( (BMSallocBufferMemory(SCIPbuffer(scip), (ptr)) == NULL) \
129  ? SCIP_NOMEMORY : SCIP_OKAY )
130 #define SCIPallocBufferArray(scip,ptr,num) ( (BMSallocBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
131  ? SCIP_NOMEMORY : SCIP_OKAY )
132 #define SCIPallocClearBufferArray(scip,ptr,num) ( (BMSallocClearBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
133  ? SCIP_NOMEMORY : SCIP_OKAY )
134 #define SCIPreallocBufferArray(scip,ptr,num) ( (BMSreallocBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
135  ? SCIP_NOMEMORY : SCIP_OKAY )
136 #define SCIPduplicateBuffer(scip,ptr,source) ( (BMSduplicateBufferMemory(SCIPbuffer(scip), (ptr), (source), (size_t)sizeof(**(ptr))) \
137  ? SCIP_NOMEMORY : SCIP_OKAY )
138 #define SCIPduplicateBufferArray(scip,ptr,source,num) ( (BMSduplicateBufferMemoryArray(SCIPbuffer(scip), (ptr), (source), (num)) == NULL) \
139  ? SCIP_NOMEMORY : SCIP_OKAY )
140 #define SCIPfreeBuffer(scip,ptr) BMSfreeBufferMemorySize(SCIPbuffer(scip), (ptr))
141 #define SCIPfreeBufferNull(scip,ptr) BMSfreeBufferMemoryNull(SCIPbuffer(scip), (ptr))
142 #define SCIPfreeBufferArray(scip,ptr) BMSfreeBufferMemoryArray(SCIPbuffer(scip), (ptr))
143 #define SCIPfreeBufferArrayNull(scip,ptr) BMSfreeBufferMemoryArrayNull(SCIPbuffer(scip), (ptr))
144 
145 
146 #define SCIPallocCleanBuffer(scip,ptr) ( (BMSallocBufferMemory(SCIPcleanbuffer(scip), (ptr)) == NULL) \
147  ? SCIP_NOMEMORY : SCIP_OKAY )
148 #define SCIPallocCleanBufferArray(scip,ptr,num) ( (BMSallocBufferMemoryArray(SCIPcleanbuffer(scip), (ptr), (num)) == NULL) \
149  ? SCIP_NOMEMORY : SCIP_OKAY )
150 #define SCIPfreeCleanBuffer(scip,ptr) BMSfreeBufferMemorySize(SCIPcleanbuffer(scip), (ptr))
151 #define SCIPfreeCleanBufferNull(scip,ptr) BMSfreeBufferMemoryNull(SCIPcleanbuffer(scip), (ptr))
152 #define SCIPfreeCleanBufferArray(scip,ptr) BMSfreeBufferMemoryArray(SCIPcleanbuffer(scip), (ptr))
153 #define SCIPfreeCleanBufferArrayNull(scip,ptr) BMSfreeBufferMemoryArrayNull(SCIPcleanbuffer(scip), (ptr))
154 
155 
156 /* Memory Management Functions
157  *
158  *
159  */
160 
161 /** returns block memory to use at the current time
162  *
163  * @return the block memory to use at the current time.
164  */
165 extern
167  SCIP* scip /**< SCIP data structure */
168  );
169 
170 /** returns buffer memory for short living temporary objects
171  *
172  * @return the buffer memory for short living temporary objects
173  */
174 extern
176  SCIP* scip /**< SCIP data structure */
177  );
178 
179 /** returns clean buffer memory for short living temporary objects initialized to all zero
180  *
181  * @return the buffer memory for short living temporary objects initialized to all zero
182  */
183 extern
185  SCIP* scip /**< SCIP data structure */
186  );
187 
188 /** returns the total number of bytes used in block and buffer memory
189  *
190  * @return the total number of bytes used in block and buffer memory.
191  */
192 extern
194  SCIP* scip /**< SCIP data structure */
195  );
196 
197 /** returns the total number of bytes in block and buffer memory
198  *
199  * @return the total number of bytes in block and buffer memory.
200  */
201 extern
203  SCIP* scip /**< SCIP data structure */
204  );
205 
206 /** returns the estimated number of bytes used by external software, e.g., the LP solver
207  *
208  * @return the estimated number of bytes used by external software, e.g., the LP solver.
209  */
210 extern
212  SCIP* scip /**< SCIP data structure */
213  );
214 
215 /** calculate memory size for dynamically allocated arrays
216  *
217  * @return the memory size for dynamically allocated arrays.
218  */
219 extern
221  SCIP* scip, /**< SCIP data structure */
222  int num /**< minimum number of entries to store */
223  );
224 
225 /** extends a dynamically allocated block memory array to be able to store at least the given number of elements;
226  * use SCIPensureBlockMemoryArray() define to call this method!
227  *
228  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
229  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
230  */
231 extern
233  SCIP* scip, /**< SCIP data structure */
234  void** arrayptr, /**< pointer to dynamically sized array */
235  size_t elemsize, /**< size in bytes of each element in array */
236  int* arraysize, /**< pointer to current array size */
237  int minsize /**< required minimal array size */
238  );
239 
240 /** prints output about used memory */
241 extern
243  SCIP* scip /**< SCIP data structure */
244  );
245 
246 /* @} */
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #endif
internal methods for branch and bound tree
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:210
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
type definitions for return codes for SCIP methods
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:128
SCIP_RETCODE SCIPensureBlockMemoryArray_call(SCIP *scip, void **arrayptr, size_t elemsize, int *arraysize, int minsize)
Definition: scip_mem.c:226
void SCIPprintMemoryDiagnostic(SCIP *scip)
Definition: scip_mem.c:252
BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip_mem.c:143
type definitions for SCIP&#39;s main datastructure
internal miscellaneous methods
internal methods for global SCIP settings
SCIP main data structure.
BMS_BUFMEM * SCIPcleanbuffer(SCIP *scip)
Definition: scip_mem.c:157
internal methods for problem variables
methods for debugging
datastructures for problem statistics
SCIP_Longint SCIPgetMemTotal(SCIP *scip)
Definition: scip_mem.c:184
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:171
internal methods for main solving loop and node processing
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:197
internal methods for constraints and constraint handlers
#define SCIP_Longint
Definition: def.h:135
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:419
memory allocation routines