23 #include "klu2_internal.h"
31 template <
typename Int>
32 size_t KLU_add_size_t (
size_t a,
size_t b, Int *ok)
34 (*ok) = (*ok) && ((a + b) >= MAX (a,b)) ;
35 return ((*ok) ? (a + b) : ((
size_t) -1)) ;
44 template <
typename Int>
45 size_t KLU_mult_size_t (
size_t a,
size_t k, Int *ok)
48 for (i = 0 ; i < k ; i++)
50 s = KLU_add_size_t (s, a, ok) ;
52 return ((*ok) ? s : ((
size_t) -1)) ;
73 template <
typename Entry,
typename Int>
80 KLU_common<Entry, Int> *Common
94 Common->status = KLU_INVALID ;
97 else if (n >= INT_MAX)
101 Common->status = KLU_TOO_LARGE ;
107 s = KLU_mult_size_t (MAX (1,n), size, &ok) ;
108 p = ok ? ((Common->malloc_memory) (s)) : NULL ;
112 Common->status = KLU_OUT_OF_MEMORY ;
116 Common->memusage += s ;
117 Common->mempeak = MAX (Common->mempeak, Common->memusage) ;
134 template <
typename Entry,
typename Int>
143 KLU_common<Entry, Int> *Common
148 if (p != NULL && Common != NULL)
152 (Common->free_memory) (p) ;
153 s = KLU_mult_size_t (MAX (1,n), size, &ok) ;
154 Common->memusage -= s ;
183 template <
typename Entry,
typename Int>
193 KLU_common<Entry, Int> *Common
207 Common->status = KLU_INVALID ;
213 p = KLU_malloc (nnew, size, Common) ;
215 else if (nnew >= INT_MAX)
218 Common->status = KLU_TOO_LARGE ;
224 snew = KLU_mult_size_t (MAX (1,nnew), size, &ok) ;
225 sold = KLU_mult_size_t (MAX (1,nold), size, &ok) ;
226 pnew = ok ? ((Common->realloc_memory) (p, snew)) : NULL ;
230 Common->status = KLU_OUT_OF_MEMORY ;
235 Common->memusage += (snew - sold) ;
236 Common->mempeak = MAX (Common->mempeak, Common->memusage) ;
const int size
Definition: klu2_simple.cpp:50