1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2021 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 mem.c
17 * @ingroup OTHER_CFILES
18 * @brief block memory pools and memory buffers
19 * @author Tobias Achterberg
20 * @author Gerald Gamrath
21 */
22
23 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
24
25 #include <assert.h>
26
27 #include "scip/def.h"
28 #include "scip/mem.h"
29 #include "scip/pub_message.h"
30
31
32
33 /** creates block and buffer memory structures */
SCIPmemCreate(SCIP_MEM ** mem)34 SCIP_RETCODE SCIPmemCreate(
35 SCIP_MEM** mem /**< pointer to block and buffer memory structure */
36 )
37 {
38 assert(mem != NULL);
39
40 SCIP_ALLOC( BMSallocMemory(mem) );
41
42 /* alloc block memory */
43 SCIP_ALLOC( (*mem)->setmem = BMScreateBlockMemory(1, 10) );
44 SCIP_ALLOC( (*mem)->probmem = BMScreateBlockMemory(1, 10) );
45
46 /* alloc memory buffers */
47 SCIP_ALLOC( (*mem)->buffer = BMScreateBufferMemory(SCIP_DEFAULT_MEM_ARRAYGROWFAC, SCIP_DEFAULT_MEM_ARRAYGROWINIT, FALSE) );
48 SCIP_ALLOC( (*mem)->cleanbuffer = BMScreateBufferMemory(SCIP_DEFAULT_MEM_ARRAYGROWFAC, SCIP_DEFAULT_MEM_ARRAYGROWINIT, TRUE) );
49
50 SCIPdebugMessage("created setmem block memory at <%p>\n", (void*)(*mem)->setmem);
51 SCIPdebugMessage("created probmem block memory at <%p>\n", (void*)(*mem)->probmem);
52
53 SCIPdebugMessage("created buffer memory at <%p>\n", (void*)(*mem)->buffer);
54 SCIPdebugMessage("created clean buffer memory at <%p>\n", (void*)(*mem)->cleanbuffer);
55
56 return SCIP_OKAY;
57 }
58
59 /** frees block and buffer memory structures */
SCIPmemFree(SCIP_MEM ** mem)60 SCIP_RETCODE SCIPmemFree(
61 SCIP_MEM** mem /**< pointer to block and buffer memory structure */
62 )
63 {
64 assert(mem != NULL);
65 if( *mem == NULL )
66 return SCIP_OKAY;
67
68 /* free memory buffers */
69 BMSdestroyBufferMemory(&(*mem)->cleanbuffer);
70 BMSdestroyBufferMemory(&(*mem)->buffer);
71
72 /* print unfreed memory */
73 #ifndef NDEBUG
74 (void) BMSblockMemoryCheckEmpty((*mem)->setmem);
75 (void) BMSblockMemoryCheckEmpty((*mem)->probmem);
76 #endif
77
78 /* free block memory */
79 BMSdestroyBlockMemory(&(*mem)->probmem);
80 BMSdestroyBlockMemory(&(*mem)->setmem);
81
82 BMSfreeMemory(mem);
83
84 return SCIP_OKAY;
85 }
86
87 /** returns the total number of bytes used in block and buffer memory */
SCIPmemGetUsed(SCIP_MEM * mem)88 SCIP_Longint SCIPmemGetUsed(
89 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
90 )
91 {
92 assert(mem != NULL);
93
94 return BMSgetBlockMemoryUsed(mem->setmem) + BMSgetBlockMemoryUsed(mem->probmem)
95 + BMSgetBufferMemoryUsed(mem->buffer) + BMSgetBufferMemoryUsed(mem->cleanbuffer);
96 }
97
98 /** returns the total number of bytes in block and buffer memory */
SCIPmemGetTotal(SCIP_MEM * mem)99 SCIP_Longint SCIPmemGetTotal(
100 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
101 )
102 {
103 assert(mem != NULL);
104
105 return BMSgetBlockMemoryAllocated(mem->setmem) + BMSgetBlockMemoryAllocated(mem->probmem)
106 + BMSgetBufferMemoryUsed(mem->buffer) + BMSgetBufferMemoryUsed(mem->cleanbuffer);
107 }
108
109 /** returns the maximal number of used bytes in block memory */
SCIPmemGetUsedBlockmemoryMax(SCIP_MEM * mem)110 SCIP_Longint SCIPmemGetUsedBlockmemoryMax(
111 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
112 )
113 {
114 assert(mem != NULL);
115
116 return BMSgetBlockMemoryUsedMax(mem->setmem) + BMSgetBlockMemoryUsedMax(mem->probmem);
117 }
118
119 /** returns the maximal number of allocated but not used bytes in block memory */
SCIPmemGetUnusedBlockmemoryMax(SCIP_MEM * mem)120 SCIP_Longint SCIPmemGetUnusedBlockmemoryMax(
121 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
122 )
123 {
124 assert(mem != NULL);
125
126 return BMSgetBlockMemoryUnusedMax(mem->setmem) + BMSgetBlockMemoryUnusedMax(mem->probmem);
127 }
128
129 /** returns the maximal number of allocated bytes in block memory */
SCIPmemGetAllocatedBlockmemoryMax(SCIP_MEM * mem)130 SCIP_Longint SCIPmemGetAllocatedBlockmemoryMax(
131 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
132 )
133 {
134 assert(mem != NULL);
135
136 return BMSgetBlockMemoryAllocatedMax(mem->setmem) + BMSgetBlockMemoryAllocatedMax(mem->probmem);
137 }
138