VirtualBox

source: vbox/trunk/include/iprt/mempool.h@ 67815

Last change on this file since 67815 was 62473, checked in by vboxsync, 8 years ago

(C) 2016

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/** @file
2 * IPRT - Memory Allocation Pool.
3 */
4
5/*
6 * Copyright (C) 2009-2016 Oracle Corporation
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_mempool_h
27#define ___iprt_mempool_h
28
29#include <iprt/types.h>
30
31RT_C_DECLS_BEGIN
32
33/**
34 * Creates a new memory pool.
35 *
36 * @returns IPRT status code.
37 *
38 * @param phMemPool Where to return the handle to the new memory
39 * pool.
40 * @param pszName The name of the pool (for debug purposes).
41 */
42RTDECL(int) RTMemPoolCreate(PRTMEMPOOL phMemPool, const char *pszName);
43
44/**
45 * Destroys the specified pool, freeing all the memory it contains.
46 *
47 * @returns IPRT status code.
48 *
49 * @param hMemPool The handle to the pool. The nil handle and
50 * RTMEMPOOL_DEFAULT are quietly ignored (retval
51 * VINF_SUCCESS).
52 */
53RTDECL(int) RTMemPoolDestroy(RTMEMPOOL hMemPool);
54
55/**
56 * Allocates memory.
57 *
58 * @returns Pointer to the allocated memory.
59 * @returns NULL on failure.
60 *
61 * @param hMemPool Handle to the pool to allocate the memory from.
62 * @param cb Size in bytes of the memory block to allocated.
63 */
64RTDECL(void *) RTMemPoolAlloc(RTMEMPOOL hMemPool, size_t cb) RT_NO_THROW_PROTO;
65
66/**
67 * Allocates zero'd memory.
68 *
69 * Instead of memset(pv, 0, sizeof()) use this when you want zero'd
70 * memory. This keeps the code smaller and the heap can skip the memset
71 * in about 0.42% of calls :-).
72 *
73 * @returns Pointer to the allocated memory.
74 * @returns NULL on failure.
75 *
76 * @param hMemPool Handle to the pool to allocate the memory from.
77 * @param cb Size in bytes of the memory block to allocated.
78 */
79RTDECL(void *) RTMemPoolAllocZ(RTMEMPOOL hMemPool, size_t cb) RT_NO_THROW_PROTO;
80
81/**
82 * Duplicates a chunk of memory into a new heap block.
83 *
84 * @returns New heap block with the duplicate data.
85 * @returns NULL if we're out of memory.
86 *
87 * @param hMemPool Handle to the pool to allocate the memory from.
88 * @param pvSrc The memory to duplicate.
89 * @param cb The amount of memory to duplicate.
90 */
91RTDECL(void *) RTMemPoolDup(RTMEMPOOL hMemPool, const void *pvSrc, size_t cb) RT_NO_THROW_PROTO;
92
93/**
94 * Duplicates a chunk of memory into a new heap block with some
95 * additional zeroed memory.
96 *
97 * @returns New heap block with the duplicate data.
98 * @returns NULL if we're out of memory.
99 *
100 * @param hMemPool Handle to the pool to allocate the memory from.
101 * @param pvSrc The memory to duplicate.
102 * @param cbSrc The amount of memory to duplicate.
103 * @param cbExtra The amount of extra memory to allocate and zero.
104 */
105RTDECL(void *) RTMemPoolDupEx(RTMEMPOOL hMemPool, const void *pvSrc, size_t cbSrc, size_t cbExtra) RT_NO_THROW_PROTO;
106
107/**
108 * Reallocates memory.
109 *
110 * @returns Pointer to the allocated memory.
111 * @returns NULL on failure.
112 *
113 * @param hMemPool Handle to the pool containing the old memory.
114 * @param pvOld The memory block to reallocate.
115 * @param cbNew The new block size (in bytes).
116 */
117RTDECL(void *) RTMemPoolRealloc(RTMEMPOOL hMemPool, void *pvOld, size_t cbNew) RT_NO_THROW_PROTO;
118
119/**
120 * Frees memory allocated from a pool.
121 *
122 * @param hMemPool Handle to the pool containing the memory. Passing
123 * NIL here is fine, but it may come at a slight
124 * performance cost.
125 * @param pv Pointer to memory block.
126 *
127 * @remarks This is the same a RTMemPoolRelease but included here as a separate
128 * function to simplify code migration.
129 */
130RTDECL(void) RTMemPoolFree(RTMEMPOOL hMemPool, void *pv) RT_NO_THROW_PROTO;
131
132/**
133 * Retains a reference to a memory block in a pool.
134 *
135 * @returns New reference count, UINT32_MAX on error (asserted).
136 *
137 * @param pv Pointer to memory block.
138 */
139RTDECL(uint32_t) RTMemPoolRetain(void *pv) RT_NO_THROW_PROTO;
140
141/**
142 * Releases a reference to a memory block in a pool.
143 *
144 * @returns New reference count, UINT32_MAX on error (asserted).
145 *
146 * @param hMemPool Handle to the pool containing the memory. Passing
147 * NIL here is fine, but it may come at a slight
148 * performance cost.
149 * @param pv Pointer to memory block.
150 */
151RTDECL(uint32_t) RTMemPoolRelease(RTMEMPOOL hMemPool, void *pv) RT_NO_THROW_PROTO;
152
153/**
154 * Get the current reference count.
155 *
156 * @returns The reference count, UINT32_MAX on error (asserted).
157 * @param pv Pointer to memory block.
158 */
159RTDECL(uint32_t) RTMemPoolRefCount(void *pv) RT_NO_THROW_PROTO;
160
161
162RT_C_DECLS_END
163
164#endif
165
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