Scippy

SCIP

Solving Constraint Integer Programs

mem.c
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-2024 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 */
44 SCIP_MEM** mem /**< pointer to block and buffer memory structure */
45 )
46{
47 assert(mem != NULL);
48
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 */
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 */
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 */
98 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
99 )
100{
101 assert(mem != NULL);
102
105}
106
107/** returns the total number of bytes in block and buffer memory */
109 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
110 )
111{
112 assert(mem != NULL);
113
116}
117
118/** returns the maximal number of used bytes in block memory */
120 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
121 )
122{
123 assert(mem != NULL);
124
126}
127
128/** returns the maximal number of allocated but not used bytes in block memory */
130 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
131 )
132{
133 assert(mem != NULL);
134
136}
137
138/** returns the maximal number of allocated bytes in block memory */
140 SCIP_MEM* mem /**< pointer to block and buffer memory structure */
141 )
142{
143 assert(mem != NULL);
144
146}
common defines and data types used in all packages of SCIP
#define NULL
Definition: def.h:266
#define SCIP_Longint
Definition: def.h:157
#define SCIP_DEFAULT_MEM_ARRAYGROWINIT
Definition: def.h:307
#define SCIP_ALLOC(x)
Definition: def.h:384
#define TRUE
Definition: def.h:93
#define FALSE
Definition: def.h:94
#define SCIP_DEFAULT_MEM_ARRAYGROWFAC
Definition: def.h:306
SCIP_Longint SCIPmemGetUsedBlockmemoryMax(SCIP_MEM *mem)
Definition: mem.c:119
SCIP_Longint SCIPmemGetUnusedBlockmemoryMax(SCIP_MEM *mem)
Definition: mem.c:129
SCIP_Longint SCIPmemGetTotal(SCIP_MEM *mem)
Definition: mem.c:108
SCIP_RETCODE SCIPmemCreate(SCIP_MEM **mem)
Definition: mem.c:43
SCIP_Longint SCIPmemGetUsed(SCIP_MEM *mem)
Definition: mem.c:97
SCIP_Longint SCIPmemGetAllocatedBlockmemoryMax(SCIP_MEM *mem)
Definition: mem.c:139
SCIP_RETCODE SCIPmemFree(SCIP_MEM **mem)
Definition: mem.c:69
methods for block memory pools and memory buffers
long long BMSgetBufferMemoryUsed(const BMS_BUFMEM *buffer)
Definition: memory.c:3139
#define BMSfreeMemory(ptr)
Definition: memory.h:145
#define BMSgetBlockMemoryUsedMax(mem)
Definition: memory.h:476
#define BMScreateBlockMemory(csz, gbf)
Definition: memory.h:447
#define BMSdestroyBlockMemory(mem)
Definition: memory.h:449
#define BMSgetBlockMemoryUnusedMax(mem)
Definition: memory.h:477
#define BMSgetBlockMemoryUsed(mem)
Definition: memory.h:474
#define BMScreateBufferMemory(fac, init, clean)
Definition: memory.h:747
#define BMSgetBlockMemoryAllocated(mem)
Definition: memory.h:473
#define BMSgetBlockMemoryAllocatedMax(mem)
Definition: memory.h:478
#define BMSblockMemoryCheckEmpty(mem)
Definition: memory.h:481
#define BMSdestroyBufferMemory(mem)
Definition: memory.h:748
#define BMSallocMemory(ptr)
Definition: memory.h:118
public methods for message output
#define SCIPdebugMessage
Definition: pub_message.h:96
BMS_BLKMEM * setmem
Definition: struct_mem.h:48
BMS_BUFMEM * buffer
Definition: struct_mem.h:50
BMS_BUFMEM * cleanbuffer
Definition: struct_mem.h:51
BMS_BLKMEM * probmem
Definition: struct_mem.h:49
@ SCIP_OKAY
Definition: type_retcode.h:42
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63