diff --git a/Common/interface/DataBlobImpl.hpp b/Common/interface/DataBlobImpl.hpp index 4566c3c72..51e78b7f5 100644 --- a/Common/interface/DataBlobImpl.hpp +++ b/Common/interface/DataBlobImpl.hpp @@ -34,6 +34,7 @@ #include "../../Primitives/interface/BasicTypes.h" #include "../../Primitives/interface/DataBlob.h" #include "../../Primitives/interface/MemoryAllocator.h" +#include "STDAllocator.hpp" #include "RefCntAutoPtr.hpp" #include "ObjectBase.hpp" @@ -47,6 +48,7 @@ class DataBlobImpl final : public Diligent::ObjectBase typedef ObjectBase TBase; static RefCntAutoPtr Create(size_t InitialSize = 0, const void* pData = nullptr); + static RefCntAutoPtr Create(IMemoryAllocator* pAllocator, size_t InitialSize = 0, const void* pData = nullptr); static RefCntAutoPtr MakeCopy(const IDataBlob* pDataBlob); ~DataBlobImpl() override; @@ -81,10 +83,13 @@ class DataBlobImpl final : public Diligent::ObjectBase template friend class MakeNewRCObj; - explicit DataBlobImpl(IReferenceCounters* pRefCounters, size_t InitialSize = 0, const void* pData = nullptr); + DataBlobImpl(IReferenceCounters* pRefCounters, + IMemoryAllocator& Allocator, + size_t InitialSize = 0, + const void* pData = nullptr); private: - std::vector m_DataBuff; + std::vector> m_DataBuff; }; class DataBlobAllocatorAdapter final : public IMemoryAllocator diff --git a/Common/src/DataBlobImpl.cpp b/Common/src/DataBlobImpl.cpp index 21ae38c19..2095ac669 100644 --- a/Common/src/DataBlobImpl.cpp +++ b/Common/src/DataBlobImpl.cpp @@ -27,15 +27,23 @@ #include "pch.h" #include "DataBlobImpl.hpp" +#include "DefaultRawMemoryAllocator.hpp" #include namespace Diligent { +RefCntAutoPtr DataBlobImpl::Create(IMemoryAllocator* pAllocator, size_t InitialSize, const void* pData) +{ + if (pAllocator == nullptr) + pAllocator = &DefaultRawMemoryAllocator::GetAllocator(); + return RefCntAutoPtr{MakeNewRCObj()(*pAllocator, InitialSize, pData)}; +} + RefCntAutoPtr DataBlobImpl::Create(size_t InitialSize, const void* pData) { - return RefCntAutoPtr{MakeNewRCObj()(InitialSize, pData)}; + return Create(nullptr, InitialSize, pData); } RefCntAutoPtr DataBlobImpl::MakeCopy(const IDataBlob* pDataBlob) @@ -46,9 +54,12 @@ RefCntAutoPtr DataBlobImpl::MakeCopy(const IDataBlob* pDataBlob) return Create(pDataBlob->GetSize(), pDataBlob->GetConstDataPtr()); } -DataBlobImpl::DataBlobImpl(IReferenceCounters* pRefCounters, size_t InitialSize, const void* pData) : +DataBlobImpl::DataBlobImpl(IReferenceCounters* pRefCounters, + IMemoryAllocator& Allocator, + size_t InitialSize, + const void* pData) : TBase{pRefCounters}, - m_DataBuff(InitialSize) + m_DataBuff{InitialSize, Uint8{}, STD_ALLOCATOR_RAW_MEM(Uint8, Allocator, "Allocator for vector")} { if (!m_DataBuff.empty() && pData != nullptr) {