Debian Codegraph @

external/glpk/glpenv05.c

raw symbols SCIP
1 /* glpenv05.c (memory allocation) */cxx . . $ `<file>/external/glpk/glpenv05.c`/
2
3 /***********************************************************************
4 * This code is part of GLPK (GNU Linear Programming Kit).
5 *
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
7 * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
9 * E-mail: <[email protected]>.
10 *
11 * GLPK is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 * License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************/
24
25 #include "glpapi.h"cxx . . $ `<file>/external/glpk/glpapi.h`/
26
27 /* some processors need data to be properly aligned; the macro
28 align_datasize enlarges the specified size of a data item to provide
29 a proper alignment of immediately following data */
30
31 #define align_datasizecxx . . $ `external/glpk/glpenv05.c:31:9`!(size) ((((size) + 15) / 16) * 16)
32 /* 16 bytes is sufficient in both 32- and 64-bit environments
33 (8 bytes is not sufficient in 64-bit environment due to jmp_buf) */
34
35 /***********************************************************************
36 * NAME
37 *
38 * glp_malloc - allocate memory block
39 *
40 * SYNOPSIS
41 *
42 * void *glp_malloc(int size);
43 *
44 * DESCRIPTION
45 *
46 * The routine glp_malloc allocates a memory block of size bytes long.
47 *
48 * Note that being allocated the memory block contains arbitrary data
49 * (not binary zeros).
50 *
51 * RETURNS
52 *
53 * The routine glp_malloc returns a pointer to the allocated block.
54 * To free this block the routine glp_free (not free!) must be used. */
55
56 void *glp_malloccxx . . $ glp_malloc(d1680a912d714170).(int size)
57 { ENVcxx . . $ ENV# *env = get_env_ptrcxx . . $ `external/glpk/glpenv.h:133:9`!();
58 MEMcxx . . $ MEM# *desc;
59 int size_of_desc = align_datasizecxx . . $ `external/glpk/glpenv05.c:31:9`!(sizeof(MEM));
60 if (size < 1 || size > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`! - size_of_desc)
61 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_malloc: size = %d; invalid parameter\n", size);
62 size += size_of_desc;
63 if (xlcmpcxx . . $ `external/glpk/glplib.h:61:9`!(xlsetcxx . . $ `external/glpk/glplib.h:45:9`!(size),
64 xlsubcxx . . $ `external/glpk/glplib.h:57:9`!(env->mem_limitcxx . . $ ENV#mem_limit., env->mem_totalcxx . . $ ENV#mem_total.)) > 0)
65 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_malloc: memory limit exceeded\n");
66 if (env->mem_countcxx . . $ ENV#mem_count. == INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)
67 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_malloc: too many memory blocks allocated\n");
68 desc = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size);
69 if (desc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
70 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_malloc: no memory available\n");
71 memsetcxx . . $ memset(d1de1e4fb215f1c6).(desc, '?', size);
72 desc->flagcxx . . $ MEM#flag. = MEM_MAGICcxx . . $ `external/glpk/glpenv.h:44:9`!;
73 desc->sizecxx . . $ MEM#size. = size;
74 desc->prevcxx . . $ MEM#prev. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
75 desc->nextcxx . . $ MEM#next. = env->mem_ptrcxx . . $ ENV#mem_ptr.;
76 if (desc->nextcxx . . $ MEM#next. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) desc->nextcxx . . $ MEM#next.->prevcxx . . $ MEM#prev. = desc;
77 env->mem_ptrcxx . . $ ENV#mem_ptr. = desc;
78 env->mem_countcxx . . $ ENV#mem_count.++;
79 if (env->mem_cpeakcxx . . $ ENV#mem_cpeak. < env->mem_countcxx . . $ ENV#mem_count.)
80 env->mem_cpeakcxx . . $ ENV#mem_cpeak. = env->mem_countcxx . . $ ENV#mem_count.;
81 env->mem_totalcxx . . $ ENV#mem_total. = xladdcxx . . $ `external/glpk/glplib.h:53:9`!(env->mem_totalcxx . . $ ENV#mem_total., xlsetcxx . . $ `external/glpk/glplib.h:45:9`!(size));
82 if (xlcmpcxx . . $ `external/glpk/glplib.h:61:9`!(env->mem_tpeakcxx . . $ ENV#mem_tpeak., env->mem_totalcxx . . $ ENV#mem_total.) < 0)
83 env->mem_tpeakcxx . . $ ENV#mem_tpeak. = env->mem_totalcxx . . $ ENV#mem_total.;
84 return (void *)((char *)desc + size_of_desc);
85 }
86
87 /***********************************************************************
88 * NAME
89 *
90 * glp_calloc - allocate memory block
91 *
92 * SYNOPSIS
93 *
94 * void *glp_calloc(int n, int size);
95 *
96 * DESCRIPTION
97 *
98 * The routine glp_calloc allocates a memory block of (n*size) bytes
99 * long.
100 *
101 * Note that being allocated the memory block contains arbitrary data
102 * (not binary zeros).
103 *
104 * RETURNS
105 *
106 * The routine glp_calloc returns a pointer to the allocated block.
107 * To free this block the routine glp_free (not free!) must be used. */
108
109 void *glp_calloccxx . . $ glp_calloc(e7ddb6f3a463937c).(int n, int size)
110 { if (n < 1)
111 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_calloc: n = %d; invalid parameter\n", n);
112 if (size < 1)
113 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_calloc: size = %d; invalid parameter\n", size);
114 if (n > INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`! / size)
115 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_calloc: n = %d; size = %d; array too big\n", n,
116 size);
117 return xmalloccxx . . $ `external/glpk/glpenv.h:167:9`!(n * size);
118 }
119
120 /***********************************************************************
121 * NAME
122 *
123 * glp_free - free memory block
124 *
125 * SYNOPSIS
126 *
127 * void glp_free(void *ptr);
128 *
129 * DESCRIPTION
130 *
131 * The routine glp_free frees a memory block pointed to by ptr, which
132 * was previuosly allocated by the routine glp_malloc or glp_calloc. */
133
134 void glp_freecxx . . $ glp_free(5d22bdacc48458e8).(void *ptr)
135 { ENVcxx . . $ ENV# *env = get_env_ptrcxx . . $ `external/glpk/glpenv.h:133:9`!();
136 MEMcxx . . $ MEM# *desc;
137 int size_of_desc = align_datasizecxx . . $ `external/glpk/glpenv05.c:31:9`!(sizeof(MEM));
138 if (ptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
139 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_free: ptr = %p; null pointer\n", ptr);
140 desc = (void *)((char *)ptr - size_of_desc);
141 if (desc->flagcxx . . $ MEM#flag. != MEM_MAGICcxx . . $ `external/glpk/glpenv.h:44:9`!)
142 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_free: ptr = %p; invalid pointer\n", ptr);
143 if (env->mem_countcxx . . $ ENV#mem_count. == 0 ||
144 xlcmpcxx . . $ `external/glpk/glplib.h:61:9`!(env->mem_totalcxx . . $ ENV#mem_total., xlsetcxx . . $ `external/glpk/glplib.h:45:9`!(desc->sizecxx . . $ MEM#size.)) < 0)
145 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_free: memory allocation error\n");
146 if (desc->prevcxx . . $ MEM#prev. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
147 env->mem_ptrcxx . . $ ENV#mem_ptr. = desc->nextcxx . . $ MEM#next.;
148 else
149 desc->prevcxx . . $ MEM#prev.->nextcxx . . $ MEM#next. = desc->nextcxx . . $ MEM#next.;
150 if (desc->nextcxx . . $ MEM#next. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
151 ;
152 else
153 desc->nextcxx . . $ MEM#next.->prevcxx . . $ MEM#prev. = desc->prevcxx . . $ MEM#prev.;
154 env->mem_countcxx . . $ ENV#mem_count.--;
155 env->mem_totalcxx . . $ ENV#mem_total. = xlsubcxx . . $ `external/glpk/glplib.h:57:9`!(env->mem_totalcxx . . $ ENV#mem_total., xlsetcxx . . $ `external/glpk/glplib.h:45:9`!(desc->sizecxx . . $ MEM#size.));
156 memsetcxx . . $ memset(d1de1e4fb215f1c6).(desc, '?', size_of_desc);
157 freecxx . . $ free(5d22bdacc48458e8).(desc);
158 return;
159 }
160
161 /***********************************************************************
162 * NAME
163 *
164 * glp_mem_limit - set memory usage limit
165 *
166 * SYNOPSIS
167 *
168 * void glp_mem_limit(int limit);
169 *
170 * DESCRIPTION
171 *
172 * The routine glp_mem_limit limits the amount of memory available for
173 * dynamic allocation (in GLPK routines) to limit megabytes. */
174
175 void glp_mem_limitcxx . . $ glp_mem_limit(d4f767463ce0a6b3).(int limit)
176 { ENVcxx . . $ ENV# *env = get_env_ptrcxx . . $ `external/glpk/glpenv.h:133:9`!();
177 if (limit < 0)
178 xerrorcxx . . $ `external/glpk/glpenv.h:158:9`!("glp_mem_limit: limit = %d; invalid parameter\n",
179 limit);
180 env->mem_limitcxx . . $ ENV#mem_limit. = xlmulcxx . . $ `external/glpk/glplib.h:65:9`!(xlsetcxx . . $ `external/glpk/glplib.h:45:9`!(limit), xlsetcxx . . $ `external/glpk/glplib.h:45:9`!(1 << 20));
181 return;
182 }
183
184 /***********************************************************************
185 * NAME
186 *
187 * glp_mem_usage - get memory usage information
188 *
189 * SYNOPSIS
190 *
191 * void glp_mem_usage(int *count, int *cpeak, glp_long *total,
192 * glp_long *tpeak);
193 *
194 * DESCRIPTION
195 *
196 * The routine glp_mem_usage reports some information about utilization
197 * of the memory by GLPK routines. Information is stored to locations
198 * specified by corresponding parameters (see below). Any parameter can
199 * be specified as NULL, in which case corresponding information is not
200 * stored.
201 *
202 * *count is the number of the memory blocks currently allocated by the
203 * routines xmalloc and xcalloc (one call to xmalloc or xcalloc results
204 * in allocating one memory block).
205 *
206 * *cpeak is the peak value of *count reached since the initialization
207 * of the GLPK library environment.
208 *
209 * *total is the total amount, in bytes, of the memory blocks currently
210 * allocated by the routines xmalloc and xcalloc.
211 *
212 * *tpeak is the peak value of *total reached since the initialization
213 * of the GLPK library envirionment. */
214
215 void glp_mem_usagecxx . . $ glp_mem_usage(6ca71a34c0a643f9).(int *count, int *cpeak, glp_longcxx . . $ glp_long# *total,
216 glp_longcxx . . $ glp_long# *tpeak)
217 { ENVcxx . . $ ENV# *env = get_env_ptrcxx . . $ `external/glpk/glpenv.h:133:9`!();
218 if (count != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *count = env->mem_countcxx . . $ ENV#mem_count.;
219 if (cpeak != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *cpeak = env->mem_cpeakcxx . . $ ENV#mem_cpeak.;
220 if (total != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *total = env->mem_totalcxx . . $ ENV#mem_total.;
221 if (tpeak != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) *tpeak = env->mem_tpeakcxx . . $ ENV#mem_tpeak.;
222 return;
223 }
224
225 /* eof */