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