1 /* ========================================================================== */
2 /* === UMF_mem_alloc_head_block ============================================= */
3 /* ========================================================================== */
4
5 /* -------------------------------------------------------------------------- */
6 /* UMFPACK Version 4.4, Copyright (c) 2005 by Timothy A. Davis. CISE Dept, */
7 /* Univ. of Florida. All Rights Reserved. See ../Doc/License for License. */
8 /* web: http://www.cise.ufl.edu/research/sparse/umfpack */
9 /* -------------------------------------------------------------------------- */
10
11 /* The UMF_mem_* routines manage the Numeric->Memory memory space. */
12
13 /* allocate nunits from head of Numeric->Memory. No header allocated. */
14 /* Returns the index into Numeric->Memory if successful, or 0 on failure. */
15
16 #include "umf_internal.h"
17
UMF_mem_alloc_head_block(NumericType * Numeric,Int nunits)18 GLOBAL Int UMF_mem_alloc_head_block
19 (
20 NumericType *Numeric,
21 Int nunits
22 )
23 {
24 Int p, usage ;
25 DEBUG2 (("GET BLOCK: from head, size "ID" ", nunits)) ;
26
27 ASSERT (Numeric != (NumericType *) NULL) ;
28 ASSERT (Numeric->Memory != (Unit *) NULL) ;
29
30 #ifndef NDEBUG
31 if (UMF_allocfail)
32 {
33 /* pretend to fail, to test garbage_collection */
34 DEBUGm2 (("UMF_mem_alloc_head_block: pretend to fail\n")) ;
35 UMF_allocfail = FALSE ; /* don't fail the next time */
36 return (0) ;
37 }
38 #endif
39
40 if (nunits > (Numeric->itail - Numeric->ihead))
41 {
42 DEBUG2 ((" failed\n")) ;
43 return (0) ;
44 }
45
46 /* return p as an offset from Numeric->Memory */
47 p = Numeric->ihead ;
48 Numeric->ihead += nunits ;
49
50 DEBUG2 (("p: "ID"\n", p)) ;
51 usage = Numeric->ihead + Numeric->tail_usage ;
52 Numeric->max_usage = MAX (Numeric->max_usage, usage) ;
53 return (p) ;
54 }
55