1 /* TMP_ALLOC routines using malloc in a reentrant fashion.
3 Copyright 2000, 2001 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
25 /* Each TMP_ALLOC uses __gmp_allocate_func to get a block of memory of the
26 size requested, plus a header at the start which is used to hold the
27 blocks on a linked list in the marker variable, ready for TMP_FREE to
30 Callers should try to do multiple allocs with one call, in the style of
31 TMP_ALLOC_LIMBS_2 if it's easy to arrange, since that will keep down the
32 number of separate malloc calls.
36 Could inline both TMP_ALLOC and TMP_FREE, though TMP_ALLOC would need the
37 compiler to have "inline" since it returns a value. The calls to malloc
38 will be slow though, so it hardly seems worth worrying about one extra
39 level of function call. */
42 #define HSIZ ROUND_UP_MULTIPLE (sizeof (struct tmp_reentrant_t), __TMP_ALIGN)
45 __gmp_tmp_reentrant_alloc (struct tmp_reentrant_t
**markp
, size_t size
)
50 #define P ((struct tmp_reentrant_t *) p)
52 total_size
= size
+ HSIZ
;
53 p
= (*__gmp_allocate_func
) (total_size
);
61 __gmp_tmp_reentrant_free (struct tmp_reentrant_t
*mark
)
63 struct tmp_reentrant_t
*next
;
68 (*__gmp_free_func
) ((char *) mark
, mark
->size
);