Changeset 101852 in vbox for trunk/src/libs/xpcom18a4/xpcom/glue/nsMemory.cpp
- Timestamp:
- Nov 6, 2023 11:09:45 AM (14 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/glue/nsMemory.cpp
r5522 r101852 36 36 * ***** END LICENSE BLOCK ***** */ 37 37 38 #include "nsXPCOM.h"39 38 #include "nsMemory.h" 40 #include "nsXPCOMPrivate.h"41 39 42 static nsIMemory* gMemory = nsnull; 43 44 static NS_METHOD FreeGlobalMemory(void) 45 { 46 NS_ASSERTION(gMemory, "must be not null after SetupGlobalMemory"); 47 NS_IF_RELEASE(gMemory); 48 return NS_OK; 49 } 50 51 #define ENSURE_ALLOCATOR \ 52 (gMemory ? PR_TRUE : (PRBool)(SetupGlobalMemory() != nsnull)) 53 54 static nsIMemory* 55 SetupGlobalMemory() 56 { 57 NS_ASSERTION(!gMemory, "must be called once"); 58 if (!gMemory) 59 { 60 NS_GetMemoryManager(&gMemory); 61 NS_ASSERTION(gMemory, "can't get memory manager!"); 62 if (gMemory) 63 NS_RegisterXPCOMExitRoutine(FreeGlobalMemory, 0); 64 } 65 return gMemory; 66 } 67 68 #ifdef XPCOM_GLUE 69 nsresult GlueStartupMemory() 70 { 71 NS_ASSERTION(!gMemory, "must be called once"); 72 if (!gMemory) 73 { 74 NS_GetMemoryManager(&gMemory); 75 NS_ASSERTION(gMemory, "can't get memory manager!"); 76 if (!gMemory) 77 return NS_ERROR_FAILURE; 78 } 79 return NS_OK; 80 } 81 82 void GlueShutdownMemory() 83 { 84 NS_IF_RELEASE(gMemory); 85 } 86 #endif 40 #include <iprt/mem.h> 87 41 88 42 //////////////////////////////////////////////////////////////////////////////// … … 92 46 nsMemory::Alloc(PRSize size) 93 47 { 94 if (!ENSURE_ALLOCATOR) 95 return nsnull; 96 97 return gMemory->Alloc(size); 48 return RTMemAlloc(size); 98 49 } 99 50 … … 101 52 nsMemory::Realloc(void* ptr, PRSize size) 102 53 { 103 if (!ENSURE_ALLOCATOR) 104 return nsnull; 105 106 return gMemory->Realloc(ptr, size); 54 return RTMemRealloc(ptr, size); 107 55 } 108 56 … … 110 58 nsMemory::Free(void* ptr) 111 59 { 112 if (!ENSURE_ALLOCATOR) 113 return; 114 115 gMemory->Free(ptr); 116 } 117 118 NS_COM nsresult 119 nsMemory::HeapMinimize(PRBool aImmediate) 120 { 121 if (!ENSURE_ALLOCATOR) 122 return NS_ERROR_FAILURE; 123 124 return gMemory->HeapMinimize(aImmediate); 60 RTMemFree(ptr); 125 61 } 126 62 … … 128 64 nsMemory::Clone(const void* ptr, PRSize size) 129 65 { 130 if (!ENSURE_ALLOCATOR) 131 return nsnull; 132 133 void* newPtr = gMemory->Alloc(size); 134 if (newPtr) 135 memcpy(newPtr, ptr, size); 136 return newPtr; 137 } 138 139 NS_COM nsIMemory* 140 nsMemory::GetGlobalMemoryService() 141 { 142 if (!ENSURE_ALLOCATOR) 143 return nsnull; 144 145 nsIMemory* result = gMemory; 146 NS_IF_ADDREF(result); 147 return result; 66 return RTMemDup(ptr, size); 148 67 } 149 68
Note:
See TracChangeset
for help on using the changeset viewer.