|
@@ -98,3 +98,31 @@ DxcThreadMalloc::DxcThreadMalloc(IMalloc *pMallocOrNull) throw() {
|
|
DxcThreadMalloc::~DxcThreadMalloc() {
|
|
DxcThreadMalloc::~DxcThreadMalloc() {
|
|
DxcSwapThreadMalloc(pPrior, nullptr);
|
|
DxcSwapThreadMalloc(pPrior, nullptr);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+void* DxcNew(std::size_t size) throw() {
|
|
|
|
+ void *ptr;
|
|
|
|
+ IMalloc* iMalloc = DxcGetThreadMallocNoRef();
|
|
|
|
+ if (iMalloc != nullptr) {
|
|
|
|
+ ptr = iMalloc->Alloc(size);
|
|
|
|
+ } else {
|
|
|
|
+ // DxcGetThreadMallocNoRef() returning null means the operator is called before DllMain
|
|
|
|
+ // where the g_pDefaultMalloc is initialized, for example from CRT libraries when
|
|
|
|
+ // static linking is enabled. In that case fallback to the standard allocator
|
|
|
|
+ // and use CoTaskMemAlloc directly instead of CoGetMalloc, Alloc & Release for better perf.
|
|
|
|
+ ptr = CoTaskMemAlloc(size);
|
|
|
|
+ }
|
|
|
|
+ return ptr;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void DxcDelete(void *ptr) throw() {
|
|
|
|
+ IMalloc* iMalloc = DxcGetThreadMallocNoRef();
|
|
|
|
+ if (iMalloc != nullptr) {
|
|
|
|
+ iMalloc->Free(ptr);
|
|
|
|
+ } else {
|
|
|
|
+ // DxcGetThreadMallocNoRef() returning null means the operator is called before DllMain
|
|
|
|
+ // where the g_pDefaultMalloc is initialized, for example from CRT libraries when
|
|
|
|
+ // static linking is enabled. In that case fallback to the standard allocator
|
|
|
|
+ // and use CoTaskMemFree directly instead of CoGetMalloc, Free & Release for better perf.
|
|
|
|
+ CoTaskMemFree(ptr);
|
|
|
|
+ }
|
|
|
|
+}
|