VirtualBox

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

Last change on this file since 3251 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

File size: 6.1 KB
Line 
1/* $Id: $ */
2/** @file
3 * innotek Portable Runtime - A Simple Heap.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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#ifndef __iprt_heap_h__
23#define __iprt_heap_h__
24
25#include <iprt/cdefs.h>
26#include <iprt/types.h>
27
28__BEGIN_DECLS
29
30/**
31 * Initializes the heap.
32 *
33 * @returns IPRT status code on success.
34 * @param pHeap Where to store the heap anchor block on success.
35 * @param pvMemory Pointer to the heap memory.
36 * @param cbMemory The size of the heap memory.
37 */
38RTDECL(int) RTHeapSimpleInit(PRTHEAPSIMPLE pHeap, void *pvMemory, size_t cbMemory);
39
40/**
41 * Merge two simple heaps into one.
42 *
43 * The requiremet is of course that they next two each other memory wise.
44 *
45 * @returns IPRT status code on success.
46 * @param pHeap Where to store the handle to the merged heap on success.
47 * @param Heap1 Handle to the first heap.
48 * @param Heap2 Handle to the second heap.
49 * @remark This API isn't implemented yet.
50 */
51RTDECL(int) RTHeapSimpleMerge(PRTHEAPSIMPLE pHeap, RTHEAPSIMPLE Heap1, RTHEAPSIMPLE Heap2);
52
53/**
54 * Allocates memory from the specified simple heap.
55 *
56 * @returns Pointer to the allocated memory block on success.
57 * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.)
58 *
59 * @param Heap The heap to allocate the memory on.
60 * @param cb The requested heap block size.
61 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
62 * Must be a power of 2.
63 */
64RTDECL(void *) RTHeapSimpleAlloc(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment);
65
66/**
67 * Allocates zeroed memory from the specified simple heap.
68 *
69 * @returns Pointer to the allocated memory block on success.
70 * @returns NULL if the request cannot be satisfied. (A VERR_NO_MEMORY condition.)
71 *
72 * @param Heap The heap to allocate the memory on.
73 * @param cb The requested heap block size.
74 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
75 * Must be a power of 2.
76 */
77RTDECL(void *) RTHeapSimpleAllocZ(RTHEAPSIMPLE Heap, size_t cb, size_t cbAlignment);
78
79/**
80 * Reallocates / Allocates / Frees a heap block.
81 *
82 * @param Heap The heap. This is optional and will only be used for strict assertions.
83 * @param pv The heap block returned by RTHeapSimple. If NULL it behaves like RTHeapSimpleAlloc().
84 * @param cbNew The new size of the heap block. If NULL it behaves like RTHeapSimpleFree().
85 * @param cbAlignment The requested heap block alignment. Pass 0 for default alignment.
86 * Must be a power of 2.
87 * @remark This API isn't implemented yet.
88 */
89RTDECL(void *) RTHeapSimpleRealloc(RTHEAPSIMPLE Heap, void *pv, size_t cbNew, size_t cbAlignment);
90
91/**
92 * Reallocates / Allocates / Frees a heap block, zeroing any new bits.
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 RTHeapSimpleAllocZ().
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 *) RTHeapSimpleReallocZ(RTHEAPSIMPLE Heap, void *pv, size_t cbNew, size_t cbAlignment);
102
103/**
104 * Frees memory allocated from a simple heap.
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
108 */
109RTDECL(void) RTHeapSimpleFree(RTHEAPSIMPLE Heap, void *pv);
110
111/**
112 * Gets the size of the specified heap block.
113 *
114 * @returns The actual size of the heap block.
115 * @returns 0 if \a pv is NULL or it doesn't point to a valid heap block. An invalid \a pv
116 * can also cause traps or trigger assertions.
117 * @param Heap The heap. This is optional and will only be used for strict assertions.
118 * @param pv The heap block returned by RTHeapSimple
119 */
120RTDECL(size_t) RTHeapSimpleSize(RTHEAPSIMPLE Heap, void *pv);
121
122/**
123 * Gets the size of the heap.
124 *
125 * This size includes all the internal heap structures. So, even if the heap is
126 * empty the RTHeapSimpleGetFreeSize() will never reach the heap size returned
127 * by this function.
128 *
129 * @returns The heap size.
130 * @returns 0 if heap was safely detected as being bad.
131 * @param Heap The heap.
132 */
133RTDECL(size_t) RTHeapSimpleGetHeapSize(RTHEAPSIMPLE Heap);
134
135/**
136 * Returns the sum of all free heap blocks.
137 *
138 * This is the amount of memory you can theoretically allocate
139 * if you do allocations exactly matching the free blocks.
140 *
141 * @returns The size of the free blocks.
142 * @returns 0 if heap was safely detected as being bad.
143 * @param Heap The heap.
144 */
145RTDECL(size_t) RTHeapSimpleGetFreeSize(RTHEAPSIMPLE Heap);
146
147/**
148 * Printf like callbaclk function for RTHeapSimpleDump.
149 * @param pszFormat IPRT format string.
150 * @param ... Format arguments.
151 */
152typedef DECLCALLBACK(void) FNRTHEAPSIMPLEPRINTF(const char *pszFormat, ...);
153/** Pointer to a FNRTHEAPSIMPLEPRINTF function. */
154typedef FNRTHEAPSIMPLEPRINTF *PFNRTHEAPSIMPLEPRINTF;
155
156/**
157 * Dumps the hypervisor heap.
158 *
159 * @param Heap The heap handle.
160 * @param pfnPrintf Printf like function that groks IPRT formatting.
161 */
162RTDECL(void) RTHeapSimpleDump(RTHEAPSIMPLE Heap, PFNRTHEAPSIMPLEPRINTF pfnPrintf);
163
164__END_DECLS
165
166#endif
167
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