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-2020 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 SCIPallocMemoryArray(scip,ptr,num) ( (BMSallocMemoryArray((ptr), (num)) == NULL) \
54  ? SCIP_NOMEMORY : SCIP_OKAY )
55 #define SCIPallocClearMemoryArray(scip,ptr,num) ( (BMSallocClearMemoryArray((ptr), (num)) == NULL) \
56  ? SCIP_NOMEMORY : SCIP_OKAY )
57 #define SCIPallocMemorySize(scip,ptr,size) ( (BMSallocMemorySize((ptr), (size)) == NULL) \
58  ? SCIP_NOMEMORY : SCIP_OKAY )
59 #define SCIPreallocMemoryArray(scip,ptr,newnum) ( (BMSreallocMemoryArray((ptr), (newnum)) == NULL) \
60  ? SCIP_NOMEMORY : SCIP_OKAY )
61 #define SCIPreallocMemorySize(scip,ptr,newsize) ( (BMSreallocMemorySize((ptr), (newsize)) == NULL) \
62  ? SCIP_NOMEMORY : SCIP_OKAY )
63 #define SCIPduplicateMemory(scip, ptr, source) ( (BMSduplicateMemory((ptr), (source)) == NULL) \
64  ? SCIP_NOMEMORY : SCIP_OKAY )
65 #define SCIPduplicateMemoryArray(scip, ptr, source, num) ( (BMSduplicateMemoryArray((ptr), (source), (num)) == NULL) \
66  ? SCIP_NOMEMORY : SCIP_OKAY )
67 #define SCIPfreeMemory(scip,ptr) BMSfreeMemory(ptr)
68 #define SCIPfreeMemoryNull(scip,ptr) BMSfreeMemoryNull(ptr)
69 #define SCIPfreeMemoryArray(scip,ptr) BMSfreeMemoryArray(ptr)
70 #define SCIPfreeMemoryArrayNull(scip,ptr) BMSfreeMemoryArrayNull(ptr)
71 #define SCIPfreeMemorySize(scip,ptr) BMSfreeMemorySize(ptr)
72 #define SCIPfreeMemorySizeNull(scip,ptr) BMSfreeMemorySizeNull(ptr)
73 
74 /* Block Memory Management Macros
75  *
76  */
77 
78 #define SCIPallocBlockMemory(scip,ptr) ( (BMSallocBlockMemory(SCIPblkmem(scip), (ptr)) == NULL) \
79  ? SCIP_NOMEMORY : SCIP_OKAY )
80 #define SCIPallocBlockMemoryArray(scip,ptr,num) ( (BMSallocBlockMemoryArray(SCIPblkmem(scip), (ptr), (num)) == NULL) \
81  ? SCIP_NOMEMORY : SCIP_OKAY )
82 #define SCIPallocBlockMemorySize(scip,ptr,size) ( (BMSallocBlockMemorySize(SCIPblkmem(scip), (ptr), (size)) == NULL) \
83  ? SCIP_NOMEMORY : SCIP_OKAY )
84 #define SCIPallocClearBlockMemoryArray(scip,ptr,num) ( (BMSallocClearBlockMemoryArray(SCIPblkmem(scip), (ptr), (num)) == NULL) \
85  ? SCIP_NOMEMORY : SCIP_OKAY )
86 #define SCIPreallocBlockMemoryArray(scip,ptr,oldnum,newnum) ( (BMSreallocBlockMemoryArray(SCIPblkmem(scip), (ptr), (oldnum), (newnum)) == NULL) \
87  ? SCIP_NOMEMORY : SCIP_OKAY )
88 #define SCIPreallocBlockMemorySize(scip,ptr,oldsize,newsize) ( (BMSreallocBlockMemorySize(SCIPblkmem(scip), (ptr), (oldsize), (newsize)) == NULL) \
89  ? SCIP_NOMEMORY : SCIP_OKAY )
90 #define SCIPduplicateBlockMemory(scip, ptr, source) ( (BMSduplicateBlockMemory(SCIPblkmem(scip), (ptr), (source)) == NULL) \
91  ? SCIP_NOMEMORY : SCIP_OKAY )
92 #define SCIPduplicateBlockMemoryArray(scip, ptr, source, num) ( (BMSduplicateBlockMemoryArray(SCIPblkmem(scip), (ptr), (source), (num)) == NULL) \
93  ? SCIP_NOMEMORY : SCIP_OKAY )
94 #define SCIPensureBlockMemoryArray(scip,ptr,arraysizeptr,minsize) ( (SCIPensureBlockMemoryArray_call((scip), (void**)(ptr), sizeof(**(ptr)), (arraysizeptr), (minsize))) )
95 #define SCIPfreeBlockMemory(scip,ptr) BMSfreeBlockMemory(SCIPblkmem(scip), (ptr))
96 #define SCIPfreeBlockMemoryNull(scip,ptr) BMSfreeBlockMemoryNull(SCIPblkmem(scip), (ptr))
97 #define SCIPfreeBlockMemoryArray(scip,ptr,num) BMSfreeBlockMemoryArray(SCIPblkmem(scip), (ptr), (num))
98 #define SCIPfreeBlockMemoryArrayNull(scip,ptr,num) BMSfreeBlockMemoryArrayNull(SCIPblkmem(scip), (ptr), (num))
99 #define SCIPfreeBlockMemorySize(scip,ptr,size) BMSfreeBlockMemorySize(SCIPblkmem(scip), (ptr), (size))
100 #define SCIPfreeBlockMemorySizeNull(scip,ptr,size) BMSfreeBlockMemorySizeNull(SCIPblkmem(scip), (ptr), (size))
101 
102 
103 /* Buffer Memory Management Macros
104  *
105  *
106  */
107 
108 
109 #define SCIPallocBuffer(scip,ptr) ( (BMSallocBufferMemory(SCIPbuffer(scip), (ptr)) == NULL) \
110  ? SCIP_NOMEMORY : SCIP_OKAY )
111 #define SCIPallocBufferArray(scip,ptr,num) ( (BMSallocBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
112  ? SCIP_NOMEMORY : SCIP_OKAY )
113 #define SCIPallocClearBufferArray(scip,ptr,num) ( (BMSallocClearBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
114  ? SCIP_NOMEMORY : SCIP_OKAY )
115 #define SCIPreallocBufferArray(scip,ptr,num) ( (BMSreallocBufferMemoryArray(SCIPbuffer(scip), (ptr), (num)) == NULL) \
116  ? SCIP_NOMEMORY : SCIP_OKAY )
117 #define SCIPduplicateBuffer(scip,ptr,source) ( (BMSduplicateBufferMemory(SCIPbuffer(scip), (ptr), (source), (size_t)sizeof(**(ptr))) \
118  ? SCIP_NOMEMORY : SCIP_OKAY )
119 #define SCIPduplicateBufferArray(scip,ptr,source,num) ( (BMSduplicateBufferMemoryArray(SCIPbuffer(scip), (ptr), (source), (num)) == NULL) \
120  ? SCIP_NOMEMORY : SCIP_OKAY )
121 #define SCIPfreeBuffer(scip,ptr) BMSfreeBufferMemorySize(SCIPbuffer(scip), (ptr))
122 #define SCIPfreeBufferNull(scip,ptr) BMSfreeBufferMemoryNull(SCIPbuffer(scip), (ptr))
123 #define SCIPfreeBufferArray(scip,ptr) BMSfreeBufferMemoryArray(SCIPbuffer(scip), (ptr))
124 #define SCIPfreeBufferArrayNull(scip,ptr) BMSfreeBufferMemoryArrayNull(SCIPbuffer(scip), (ptr))
125 
126 
127 #define SCIPallocCleanBuffer(scip,ptr) ( (BMSallocBufferMemory(SCIPcleanbuffer(scip), (ptr)) == NULL) \
128  ? SCIP_NOMEMORY : SCIP_OKAY )
129 #define SCIPallocCleanBufferArray(scip,ptr,num) ( (BMSallocBufferMemoryArray(SCIPcleanbuffer(scip), (ptr), (num)) == NULL) \
130  ? SCIP_NOMEMORY : SCIP_OKAY )
131 #define SCIPfreeCleanBuffer(scip,ptr) BMSfreeBufferMemorySize(SCIPcleanbuffer(scip), (ptr))
132 #define SCIPfreeCleanBufferNull(scip,ptr) BMSfreeBufferMemoryNull(SCIPcleanbuffer(scip), (ptr))
133 #define SCIPfreeCleanBufferArray(scip,ptr) BMSfreeBufferMemoryArray(SCIPcleanbuffer(scip), (ptr))
134 #define SCIPfreeCleanBufferArrayNull(scip,ptr) BMSfreeBufferMemoryArrayNull(SCIPcleanbuffer(scip), (ptr))
135 
136 
137 /* Memory Management Functions
138  *
139  *
140  */
141 
142 /** returns block memory to use at the current time
143  *
144  * @return the block memory to use at the current time.
145  */
148  SCIP* scip /**< SCIP data structure */
149  );
150 
151 /** returns buffer memory for short living temporary objects
152  *
153  * @return the buffer memory for short living temporary objects
154  */
157  SCIP* scip /**< SCIP data structure */
158  );
159 
160 /** returns clean buffer memory for short living temporary objects initialized to all zero
161  *
162  * @return the buffer memory for short living temporary objects initialized to all zero
163  */
166  SCIP* scip /**< SCIP data structure */
167  );
168 
169 /** returns the total number of bytes used in block and buffer memory
170  *
171  * @return the total number of bytes used in block and buffer memory.
172  */
175  SCIP* scip /**< SCIP data structure */
176  );
177 
178 /** returns the total number of bytes in block and buffer memory
179  *
180  * @return the total number of bytes in block and buffer memory.
181  */
184  SCIP* scip /**< SCIP data structure */
185  );
186 
187 /** returns the estimated number of bytes used by external software, e.g., the LP solver
188  *
189  * @return the estimated number of bytes used by external software, e.g., the LP solver.
190  */
193  SCIP* scip /**< SCIP data structure */
194  );
195 
196 /** calculate memory size for dynamically allocated arrays
197  *
198  * @return the memory size for dynamically allocated arrays.
199  */
202  SCIP* scip, /**< SCIP data structure */
203  int num /**< minimum number of entries to store */
204  );
205 
206 /** extends a dynamically allocated block memory array to be able to store at least the given number of elements;
207  * use SCIPensureBlockMemoryArray() define to call this method!
208  *
209  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
210  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
211  */
214  SCIP* scip, /**< SCIP data structure */
215  void** arrayptr, /**< pointer to dynamically sized array */
216  size_t elemsize, /**< size in bytes of each element in array */
217  int* arraysize, /**< pointer to current array size */
218  int minsize /**< required minimal array size */
219  );
220 
221 /** prints output about used memory */
224  SCIP* scip /**< SCIP data structure */
225  );
226 
227 /** @} */
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif
#define SCIP_EXPORT
Definition: def.h:100
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_EXPORT SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:91
type definitions for return codes for SCIP methods
SCIP_EXPORT SCIP_Longint SCIPgetMemTotal(SCIP *scip)
Definition: scip_mem.c:104
type definitions for SCIP&#39;s main datastructure
SCIP_EXPORT int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip_mem.c:130
SCIP_EXPORT SCIP_RETCODE SCIPensureBlockMemoryArray_call(SCIP *scip, void **arrayptr, size_t elemsize, int *arraysize, int minsize)
Definition: scip_mem.c:146
SCIP_EXPORT BMS_BUFMEM * SCIPbuffer(SCIP *scip)
Definition: scip_mem.c:63
SCIP_EXPORT void SCIPprintMemoryDiagnostic(SCIP *scip)
Definition: scip_mem.c:172
SCIP_EXPORT BMS_BUFMEM * SCIPcleanbuffer(SCIP *scip)
Definition: scip_mem.c:77
SCIP_EXPORT BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
#define SCIP_Longint
Definition: def.h:148
SCIP_EXPORT SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:117
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:429
memory allocation routines