vbox的更動 31157 路徑 trunk/src/VBox/Runtime/r3/alloc.cpp
- 時間撮記:
- 2010-7-28 上午03:15:35 (14 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/r3/alloc.cpp
r28800 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 … … 48 48 49 49 #undef RTMemTmpAlloc 50 #undef RTMemTmpAllocTag 50 51 #undef RTMemTmpAllocZ 52 #undef RTMemTmpAllocZTag 51 53 #undef RTMemTmpFree 52 54 #undef RTMemAlloc 55 #undef RTMemAllocTag 53 56 #undef RTMemAllocZ 57 #undef RTMemAllocZTag 54 58 #undef RTMemAllocVar 59 #undef RTMemAllocVarTag 55 60 #undef RTMemAllocZVar 61 #undef RTMemAllocZVarTag 56 62 #undef RTMemRealloc 63 #undef RTMemReallocTag 57 64 #undef RTMemFree 58 65 #undef RTMemDup 66 #undef RTMemDupTag 59 67 #undef RTMemDupEx 68 #undef RTMemDupExTag 60 69 61 70 62 /** 63 * Allocates temporary memory. 64 * 65 * Temporary memory blocks are used for not too large memory blocks which 66 * are believed not to stick around for too long. Using this API instead 67 * of RTMemAlloc() not only gives the heap manager room for optimization 68 * but makes the code easier to read. 69 * 70 * @returns Pointer to the allocated memory. 71 * @returns NULL on failure. 72 * @param cb Size in bytes of the memory block to allocate. 73 */ 74 RTDECL(void *) RTMemTmpAlloc(size_t cb) RT_NO_THROW 71 RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 75 72 { 76 return RTMemAlloc (cb);73 return RTMemAllocTag(cb, pszTag); 77 74 } 78 75 79 76 80 /** 81 * Allocates zero'ed temporary memory. 82 * 83 * Same as RTMemTmpAlloc() but the memory will be zero'ed. 84 * 85 * @returns Pointer to the allocated memory. 86 * @returns NULL on failure. 87 * @param cb Size in bytes of the memory block to allocate. 88 */ 89 RTDECL(void *) RTMemTmpAllocZ(size_t cb) RT_NO_THROW 77 RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 90 78 { 91 return RTMemAllocZ (cb);79 return RTMemAllocZTag(cb, pszTag); 92 80 } 93 81 94 82 95 /** 96 * Free temporary memory. 97 * 98 * @param pv Pointer to memory block. 99 */ 100 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 83 RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW 101 84 { 102 85 RTMemFree(pv); … … 104 87 105 88 106 /** 107 * Allocates memory. 108 * 109 * @returns Pointer to the allocated memory. 110 * @returns NULL on failure. 111 * @param cb Size in bytes of the memory block to allocate. 112 */ 113 RTDECL(void *) RTMemAlloc(size_t cb) RT_NO_THROW 89 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW 114 90 { 115 91 #ifdef RTALLOC_USE_EFENCE 116 void *pv = rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, ASMReturnAddress(), NULL, 0, NULL);92 void *pv = rtR3MemAlloc("Alloc", RTMEMTYPE_RTMEMALLOC, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 117 93 118 94 #else /* !RTALLOC_USE_EFENCE */ … … 130 106 131 107 132 /** 133 * Allocates zero'ed memory. 134 * 135 * Instead of memset(pv, 0, sizeof()) use this when you want zero'ed 136 * memory. This keeps the code smaller and the heap can skip the memset 137 * in about 0.42% of the calls :-). 138 * 139 * @returns Pointer to the allocated memory. 140 * @returns NULL on failure. 141 * @param cb Size in bytes of the memory block to allocate. 142 */ 143 RTDECL(void *) RTMemAllocZ(size_t cb) RT_NO_THROW 108 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW 144 109 { 145 110 #ifdef RTALLOC_USE_EFENCE 146 void *pv = rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, ASMReturnAddress(), NULL, 0, NULL);111 void *pv = rtR3MemAlloc("AllocZ", RTMEMTYPE_RTMEMALLOCZ, cb, cb, pszTag, ASMReturnAddress(), NULL, 0, NULL); 147 112 148 113 #else /* !RTALLOC_USE_EFENCE */ … … 161 126 162 127 163 /** 164 * Wrapper around RTMemAlloc for automatically aligning variable sized 165 * allocations so that the various electric fence heaps works correctly. 166 * 167 * @returns See RTMemAlloc. 168 * @param cbUnaligned The unaligned size. 169 */ 170 RTDECL(void *) RTMemAllocVar(size_t cbUnaligned) 128 RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 171 129 { 172 130 size_t cbAligned; … … 176 134 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 177 135 #ifdef RTALLOC_USE_EFENCE 178 void *pv = rtR3MemAlloc("AllocVar", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);136 void *pv = rtR3MemAlloc("AllocVar", RTMEMTYPE_RTMEMALLOC, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL); 179 137 #else 180 void *pv = RTMemAlloc (cbAligned);138 void *pv = RTMemAllocTag(cbAligned, pszTag); 181 139 #endif 182 140 return pv; … … 184 142 185 143 186 /** 187 * Wrapper around RTMemAllocZ for automatically aligning variable sized 188 * allocations so that the various electric fence heaps works correctly. 189 * 190 * @returns See RTMemAllocZ. 191 * @param cbUnaligned The unaligned size. 192 */ 193 RTDECL(void *) RTMemAllocZVar(size_t cbUnaligned) 144 RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW 194 145 { 195 146 size_t cbAligned; … … 199 150 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *)); 200 151 #ifdef RTALLOC_USE_EFENCE 201 void *pv = rtR3MemAlloc("AllocZVar", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, ASMReturnAddress(), NULL, 0, NULL);152 void *pv = rtR3MemAlloc("AllocZVar", RTMEMTYPE_RTMEMALLOCZ, cbUnaligned, cbAligned, pszTag, ASMReturnAddress(), NULL, 0, NULL); 202 153 #else 203 void *pv = RTMemAllocZ (cbAligned);154 void *pv = RTMemAllocZTag(cbAligned, pszTag); 204 155 #endif 205 156 return pv; … … 207 158 208 159 209 /** 210 * Reallocates memory. 211 * 212 * @returns Pointer to the allocated memory. 213 * @returns NULL on failure. 214 * @param pvOld The memory block to reallocate. 215 * @param cbNew The new block size (in bytes). 216 */ 217 RTDECL(void *) RTMemRealloc(void *pvOld, size_t cbNew) RT_NO_THROW 160 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW 218 161 { 219 162 #ifdef RTALLOC_USE_EFENCE 220 void *pv = rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, ASMReturnAddress(), NULL, 0, NULL);163 void *pv = rtR3MemRealloc("Realloc", RTMEMTYPE_RTMEMREALLOC, pvOld, cbNew, pszTag, ASMReturnAddress(), NULL, 0, NULL); 221 164 222 165 #else /* !RTALLOC_USE_EFENCE */ … … 233 176 234 177 235 /** 236 * Free memory related to a virtual machine 237 * 238 * @param pv Pointer to memory block. 239 */ 240 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 178 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW 241 179 { 242 180 if (pv)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器