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