VirtualBox

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

Last change on this file since 7170 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

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

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