47 #include "klu2_internal.h"
55 template <
typename Int>
56 size_t KLU_add_size_t (
size_t a,
size_t b, Int *ok)
58 (*ok) = (*ok) && ((a + b) >= MAX (a,b)) ;
59 return ((*ok) ? (a + b) : ((
size_t) -1)) ;
68 template <
typename Int>
69 size_t KLU_mult_size_t (
size_t a,
size_t k, Int *ok)
72 for (i = 0 ; i < k ; i++)
74 s = KLU_add_size_t (s, a, ok) ;
76 return ((*ok) ? s : ((
size_t) -1)) ;
97 template <
typename Entry,
typename Int>
104 KLU_common<Entry, Int> *Common
118 Common->status = KLU_INVALID ;
121 else if (n >= INT_MAX)
125 Common->status = KLU_TOO_LARGE ;
131 s = KLU_mult_size_t (MAX (1,n), size, &ok) ;
132 p = ok ? ((Common->malloc_memory) (s)) : NULL ;
136 Common->status = KLU_OUT_OF_MEMORY ;
140 Common->memusage += s ;
141 Common->mempeak = MAX (Common->mempeak, Common->memusage) ;
158 template <
typename Entry,
typename Int>
167 KLU_common<Entry, Int> *Common
172 if (p != NULL && Common != NULL)
176 (Common->free_memory) (p) ;
177 s = KLU_mult_size_t (MAX (1,n), size, &ok) ;
178 Common->memusage -= s ;
207 template <
typename Entry,
typename Int>
217 KLU_common<Entry, Int> *Common
231 Common->status = KLU_INVALID ;
237 p = KLU_malloc (nnew, size, Common) ;
239 else if (nnew >= INT_MAX)
242 Common->status = KLU_TOO_LARGE ;
248 snew = KLU_mult_size_t (MAX (1,nnew), size, &ok) ;
249 sold = KLU_mult_size_t (MAX (1,nold), size, &ok) ;
250 pnew = ok ? ((Common->realloc_memory) (p, snew)) : NULL ;
254 Common->status = KLU_OUT_OF_MEMORY ;
259 Common->memusage += (snew - sold) ;
260 Common->mempeak = MAX (Common->mempeak, Common->memusage) ;