Changeset 31157 in vbox for trunk/src/VBox/Runtime/r0drv/alloc-r0drv.cpp
- Timestamp:
- Jul 28, 2010 3:15:35 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 64135
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/alloc-r0drv.cpp
r29250 r31157 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 81 81 82 82 83 84 /** 85 * Allocates temporary memory. 86 * 87 * Temporary memory blocks are used for not too large memory blocks which 88 * are believed not to stick around for too long. Using this API instead 89 * of RTMemAlloc() not only gives the heap manager room for optimization 90 * but makes the code easier to read. 91 * 92 * @returns Pointer to the allocated memory. 93 * @returns NULL on failure. 94 * @param cb Size in bytes of the memory block to allocated. 95 */ 96 RTDECL(void *) RTMemTmpAlloc(size_t cb) RT_NO_THROW 97 { 98 return RTMemAlloc(cb); 99 } 100 RT_EXPORT_SYMBOL(RTMemTmpAlloc); 101 102 103 /** 104 * Allocates zero'ed temporary memory. 105 * 106 * Same as RTMemTmpAlloc() but the memory will be zero'ed. 107 * 108 * @returns Pointer to the allocated memory. 109 * @returns NULL on failure. 110 * @param cb Size in bytes of the memory block to allocated. 111 */ 112 RTDECL(void *) RTMemTmpAllocZ(size_t cb) RT_NO_THROW 113 { 114 return RTMemAllocZ(cb); 115 } 116 RT_EXPORT_SYMBOL(RTMemTmpAllocZ); 117 118 119 /** 120 * Free temporary memory. 121 * 122 * @param pv Pointer to memory block. 123 */ 83 #undef RTMemTmpAlloc 84 #undef RTMemTmpAllocTag 85 #undef RTMemTmpAllocZ 86 #undef RTMemTmpAllocZTag 87 #undef RTMemTmpFree 88 #undef RTMemAlloc 89 #undef RTMemAllocTag 90 #undef RTMemAllocZ 91 #undef RTMemAllocZTag 92 #undef RTMemAllocVar 93 #undef RTMemAllocVarTag 94 #undef RTMemAllocZVar 95 #undef RTMemAllocZVarTag 96 #undef RTMemRealloc 97 #undef RTMemReallocTag 98 #undef RTMemFree 99 #undef RTMemDup 100 #undef RTMemDupTag 101 #undef RTMemDupEx 102 #undef RTMemDupExTag 103 104 105 106 RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 107 { 108 return RTMemAllocTag(cb, pszTag); 109 } 110 RT_EXPORT_SYMBOL(RTMemTmpAllocTag); 111 112 113 RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 114 { 115 return RTMemAllocZTag(cb, pszTag); 116 } 117 RT_EXPORT_SYMBOL(RTMemTmpAllocZTag); 118 119 124 120 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 125 121 { … … 129 125 130 126 131 /** 132 * Allocates memory. 133 * 134 * @returns Pointer to the allocated memory. 135 * @returns NULL on failure. 136 * @param cb Size in bytes of the memory block to allocated. 137 */ 138 RTDECL(void *) RTMemAlloc(size_t cb) RT_NO_THROW 127 128 129 130 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 139 131 { 140 132 PRTMEMHDR pHdr; … … 152 144 return NULL; 153 145 } 154 RT_EXPORT_SYMBOL(RTMemAlloc); 155 156 157 /** 158 * Allocates zero'ed memory. 159 * 160 * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed 161 * memory. This keeps the code smaller and the heap can skip the memset 162 * in about 0.42% of calls :-). 163 * 164 * @returns Pointer to the allocated memory. 165 * @returns NULL on failure. 166 * @param cb Size in bytes of the memory block to allocated. 167 */ 168 RTDECL(void *) RTMemAllocZ(size_t cb) RT_NO_THROW 146 RT_EXPORT_SYMBOL(RTMemAllocTag); 147 148 149 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 169 150 { 170 151 PRTMEMHDR pHdr; … … 184 165 return NULL; 185 166 } 186 RT_EXPORT_SYMBOL(RTMemAllocZ); 187 188 189 /** 190 * Wrapper around RTMemAlloc for automatically aligning variable sized 191 * allocations so that the various electric fence heaps works correctly. 192 * 193 * @returns See RTMemAlloc. 194 * @param cbUnaligned The unaligned size. 195 */ 196 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned) 167 RT_EXPORT_SYMBOL(RTMemAllocZTag); 168 169 170 RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) 197 171 { 198 172 size_t cbAligned; … … 201 175 else 202 176 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 203 return RTMemAlloc(cbAligned); 204 } 205 RT_EXPORT_SYMBOL(RTMemAllocVar); 206 207 208 /** 209 * Wrapper around RTMemAllocZ for automatically aligning variable sized 210 * allocations so that the various electric fence heaps works correctly. 211 * 212 * @returns See RTMemAllocZ. 213 * @param cbUnaligned The unaligned size. 214 */ 215 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned) 177 return RTMemAllocTag(cbAligned, pszTag); 178 } 179 RT_EXPORT_SYMBOL(RTMemAllocVarTag); 180 181 182 RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) 216 183 { 217 184 size_t cbAligned; … … 220 187 else 221 188 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 222 return RTMemAllocZ(cbAligned); 223 } 224 RT_EXPORT_SYMBOL(RTMemAllocZVar); 225 226 227 /** 228 * Reallocates memory. 229 * 230 * @returns Pointer to the allocated memory. 231 * @returns NULL on failure. 232 * @param pvOld The memory block to reallocate. 233 * @param cbNew The new block size (in bytes). 234 */ 235 RTDECL(void *) RTMemRealloc(void *pvOld, size_t cbNew) RT_NO_THROW 189 return RTMemAllocZTag(cbAligned, pszTag); 190 } 191 RT_EXPORT_SYMBOL(RTMemAllocZVarTag); 192 193 194 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW 236 195 { 237 196 if (!cbNew) 238 197 RTMemFree(pvOld); 239 198 else if (!pvOld) 240 return RTMemAlloc (cbNew);199 return RTMemAllocTag(cbNew, pszTag); 241 200 else 242 201 { … … 275 234 return NULL; 276 235 } 277 RT_EXPORT_SYMBOL(RTMemRealloc); 278 279 280 /** 281 * Free memory related to an virtual machine 282 * 283 * @param pv Pointer to memory block. 284 */ 236 RT_EXPORT_SYMBOL(RTMemReallocTag); 237 238 285 239 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 286 240 { … … 311 265 312 266 313 /** 314 * Allocates memory which may contain code. 315 * 316 * @returns Pointer to the allocated memory. 317 * @returns NULL on failure. 318 * @param cb Size in bytes of the memory block to allocate. 319 */ 320 RTDECL(void *) RTMemExecAlloc(size_t cb) RT_NO_THROW 267 268 269 270 271 RTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 321 272 { 322 273 PRTMEMHDR pHdr; … … 338 289 return NULL; 339 290 } 340 RT_EXPORT_SYMBOL(RTMemExecAlloc); 341 342 343 /** 344 * Free executable/read/write memory allocated by RTMemExecAlloc(). 345 * 346 * @param pv Pointer to memory block. 347 */ 291 RT_EXPORT_SYMBOL(RTMemExecAllocTag); 292 293 348 294 RTDECL(void) RTMemExecFree(void *pv) RT_NO_THROW 349 295 {
Note:
See TracChangeset
for help on using the changeset viewer.