1 #ifndef MP_HEAP_H
2 #define MP_HEAP_H
3 
4 
5 /*
6  * mpatrol
7  * A library for controlling and tracing dynamic memory allocations.
8  * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307, USA.
24  */
25 
26 
27 /*
28  * Memory heaps.  All dynamic memory allocations made by the mpatrol
29  * library are made through this module, which keeps track of each
30  * individual block of memory allocated by the low-level memory
31  * allocator.  Note that such a heap may not be (and is not guaranteed
32  * to be) composed of contiguous blocks of memory.
33  */
34 
35 
36 /*
37  * $Id: heap.h,v 1.9 2002/01/08 20:13:59 graeme Exp $
38  */
39 
40 
41 #include "config.h"
42 #include "memory.h"
43 #include "slots.h"
44 #include "tree.h"
45 
46 
47 /* A heap node belongs to a binary search tree of heap nodes, ordered
48  * by address, and contains details of a single allocated block of memory.
49  */
50 
51 typedef struct heapnode
52 {
53     treenode node; /* tree node */
54     void *block;   /* pointer to block of memory */
55     size_t size;   /* size of block of memory */
56 }
57 heapnode;
58 
59 
60 /* A heap head contains the slot table of heap nodes, whose memory blocks
61  * are allocated in the internal allocation tree.
62  */
63 
64 typedef struct heaphead
65 {
66     meminfo memory;   /* memory details */
67     slottable table;  /* table of heap nodes */
68     treeroot itree;   /* internal allocation tree */
69     treeroot dtree;   /* heap node allocation tree */
70     size_t isize;     /* internal allocation total */
71     size_t dsize;     /* heap node allocation total */
72     memaccess prot;   /* protection status */
73     size_t protrecur; /* protection recursion count */
74     char tracing;     /* heap reservation tracing status */
75 }
76 heaphead;
77 
78 
79 #ifdef __cplusplus
80 extern "C"
81 {
82 #endif /* __cplusplus */
83 
84 
85 MP_EXPORT void __mp_newheap(heaphead *);
86 MP_EXPORT void __mp_deleteheap(heaphead *);
87 MP_EXPORT heapnode *__mp_heapalloc(heaphead *, size_t, size_t, int);
88 MP_EXPORT void __mp_heapfree(heaphead *, heapnode *);
89 MP_EXPORT int __mp_heapprotect(heaphead *, memaccess);
90 
91 
92 #ifdef __cplusplus
93 }
94 #endif /* __cplusplus */
95 
96 
97 #endif /* MP_HEAP_H */
98