VirtualBox

source: vbox/trunk/include/iprt/heap.h@ 289

Last change on this file since 289 was 288, checked in by vboxsync, 18 years ago

debugged the heap.

File size: 6.4 KB
Line 
1/* $Id: $ */
2/** @file
3 * InnoTek Portable Runtime - A Simple Heap.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/* >>> heap.h */
24#ifndef __iprt_heap_h__
25#define __iprt_heap_h__
26
27#include <iprt/cdefs.h>
28#include <iprt/types.h>
29
30/* >>> types.h */
31/** Handle to a simple heap. */
32typedef struct RTHEAPSIMPLEINTERNAL *RTHEAPSIMPLE;
33/** Pointer to a handle to a simple heap. */
34typedef RTHEAPSIMPLE *PRTHEAPSIMPLE;
35
36/** NIL simple heap handle. */
37#define NIL_RTHEAPSIMPLE ((RTHEAPSIMPLE)0)
38/* <<< types.h */
39
40__BEGIN_DECLS
41
42/**
43 * Initializes the heap.
44 *
45 * @returns IPRT status code on success.
46 * @param pHeap Where to store the heap anchor block on success.
47 * @param pvMemory Pointer to the heap memory.
48 * @param cbMemory The size of the heap memory.
49 */
50RTDECL(int) RTHeapSimpleInit(PRTHEAPSIMPLE pHeap, void *pvMemory, size_t cbMemory);
51
52/**
53 * Merge two simple heaps into one.
54 *
55 * The requiremet is of course that they next two each other memory wise.
56 *
57 * @returns IPRT status code on success.
58 * @param pHeap Where to store the handle to the merged heap on success.
59 * @param Heap1 Handle to the first heap.
60 * @param Heap2 Handle to the second heap.
61 * @remark This API isn't implemented yet.
62 */
63RTDECL(int) RTHeapSimpleMerge(PRTHEAPSIMPLE pHeap, RTHEAPSIMPLE Heap1, RTHEAPSIMPLE Heap2);
64
65/**
66 * Allocates memory from the specified simple heap.
67 *
68 * @returns Pointer to the allocated memory block on success.
69 * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.)
70 *
71 * @param Heap The heap to allocate the memory on.
72 * @param cb The requested heap block size.
73 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
74 * Must be a power of 2.
75 */
76RTDECL(void *) RTHeapSimpleAlloc(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment);
77
78/**
79 * Allocates zeroed memory from the specified simple heap.
80 *
81 * @returns Pointer to the allocated memory block on success.
82 * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.)
83 *
84 * @param Heap The heap to allocate the memory on.
85 * @param cb The requested heap block size.
86 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
87 * Must be a power of 2.
88 */
89RTDECL(void *) RTHeapSimpleAllocZ(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment);
90
91/**
92 * Reallocates / Allocates / Frees a heap block.
93 *
94 * @param Heap The heap. This is optional and will only be used for strict assertions.
95 * @param pv The heap block returned by RTHeapSimple. If NULL it behaves like RTHeapSimpleAlloc().
96 * @param cbNew The new size of the heap block. If NULL it behaves like RTHeapSimpleFree().
97 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
98 * Must be a power of 2.
99 * @remark This API isn't implemented yet.
100 */
101RTDECL(void *) RTHeapSimpleRealloc(RTHEAPSIMPLE Heap, void *pv, size_t cbNew, size_t cbAlignment);
102
103/**
104 * Reallocates / Allocates / Frees a heap block, zeroing any new bits.
105 *
106 * @param Heap The heap. This is optional and will only be used for strict assertions.
107 * @param pv The heap block returned by RTHeapSimple. If NULL it behaves like RTHeapSimpleAllocZ().
108 * @param cbNew The new size of the heap block. If NULL it behaves like RTHeapSimpleFree().
109 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
110 * Must be a power of 2.
111 * @remark This API isn't implemented yet.
112 */
113RTDECL(void *) RTHeapSimpleReallocZ(RTHEAPSIMPLE Heap, void *pv, size_t cbNew, size_t cbAlignment);
114
115/**
116 * Frees memory allocated from a simple heap.
117 *
118 * @param Heap The heap. This is optional and will only be used for strict assertions.
119 * @param pv The heap block returned by RTHeapSimple
120 */
121RTDECL(void) RTHeapSimpleFree(RTHEAPSIMPLE Heap, void *pv);
122
123/**
124 * Gets the size of the specified heap block.
125 *
126 * @returns The actual size of the heap block.
127 * @returns 0 if \a pv is NULL or it doesn't point to a valid heap block. An invalid \a pv
128 * can also cause traps or trigger assertions.
129 * @param Heap The heap. This is optional and will only be used for strict assertions.
130 * @param pv The heap block returned by RTHeapSimple
131 */
132RTDECL(size_t) RTHeapSimpleSize(RTHEAPSIMPLE Heap, void *pv);
133
134/**
135 * Gets the size of the heap.
136 *
137 * This size includes all the internal heap structures. So, even if the heap is
138 * empty the RTHeapSimpleGetFreeSize() will never reach the heap size returned
139 * by this function.
140 *
141 * @returns The heap size.
142 * @returns 0 if heap was safely detected as being bad.
143 * @param Heap The heap.
144 */
145RTDECL(size_t) RTHeapSimpleGetHeapSize(RTHEAPSIMPLE Heap);
146
147/**
148 * Returns the sum of all free heap blocks.
149 *
150 * This is the amount of memory you can theoretically allocate
151 * if you do allocations exactly matching the free blocks.
152 *
153 * @returns The size of the free blocks.
154 * @returns 0 if heap was safely detected as being bad.
155 * @param Heap The heap.
156 */
157RTDECL(size_t) RTHeapSimpleGetFreeSize(RTHEAPSIMPLE Heap);
158
159/**
160 * Printf like callbaclk function for RTHeapSimpleDump.
161 * @param pszFormat IPRT format string.
162 * @param ... Format arguments.
163 */
164typedef DECLCALLBACK(void) FNRTHEAPSIMPLEPRINTF(const char *pszFormat, ...);
165/** Pointer to a FNRTHEAPSIMPLEPRINTF function. */
166typedef FNRTHEAPSIMPLEPRINTF *PFNRTHEAPSIMPLEPRINTF;
167
168/**
169 * Dumps the hypervisor heap.
170 *
171 * @param Heap The heap handle.
172 * @param pfnPrintf Printf like function that groks IPRT formatting.
173 */
174RTDECL(void) RTHeapSimpleDump(RTHEAPSIMPLE Heap, PFNRTHEAPSIMPLEPRINTF pfnPrintf);
175
176__END_DECLS
177
178#endif
179
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette