Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions Modules/Core/Common/test/itkFactoryTestLib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class TestImportImageContainer : public itk::ImportImageContainer<TElementIdenti
using typename Superclass::ElementIdentifier;
using typename Superclass::Element;

using Allocator = std::allocator<TElement>;

// Methods from itkObject
virtual ~TestImportImageContainer()
{
Expand All @@ -67,21 +65,9 @@ class TestImportImageContainer : public itk::ImportImageContainer<TElementIdenti
TElement * data;
try
{
// allocate normally only requires 1 argument.
// MSVC 6.0 makes it require 2, we set the second to be
// a null pointer which means no allocation hint
// Sun cc compiler needs a cast to assign a void pointer to another pointer
data = static_cast<TElement *>(m_Allocator.allocate(size, 0));
if (data)
{
new (data) Element[size];
}
data = new Element[size];
}
catch (...)
{
data = 0;
}
if (!data)
{
// We cannot construct an error string here because we may be out
// of memory. Do not use the exception macro.
Expand All @@ -91,7 +77,7 @@ class TestImportImageContainer : public itk::ImportImageContainer<TElementIdenti
m_TotalSize = size * sizeof(TElement);
itkTotalMemoryUsed += m_TotalSize;

m_MemoryAllocatedByAllocator = true;
m_MemoryAllocatedByTestImportImageContainer = true;

std::cout << "TestImportImageContainer: Total memory used is " << itkTotalMemoryUsed << " bytes" << std::endl;

Expand All @@ -105,16 +91,9 @@ class TestImportImageContainer : public itk::ImportImageContainer<TElementIdenti
<< typeid(TElement).name() << " totaling " << sizeof(TElement) * this->Capacity() << " bytes"
<< std::endl;

if (m_MemoryAllocatedByAllocator)
if (m_MemoryAllocatedByTestImportImageContainer)
{
TElement * ptr = this->GetImportPointer();
const TElement * const end = ptr + this->Capacity();
for (TElement * base = ptr; base < end; ++base)
{
m_Allocator.destroy(base);
}
m_Allocator.deallocate(ptr, this->Capacity());

delete[] this->GetImportPointer();
this->SetImportPointer(0);
this->SetCapacity(0);
this->SetSize(0);
Expand All @@ -130,8 +109,7 @@ class TestImportImageContainer : public itk::ImportImageContainer<TElementIdenti
private:
mutable TElementIdentifier m_TotalSize;

mutable Allocator m_Allocator;
mutable bool m_MemoryAllocatedByAllocator{ false };
mutable bool m_MemoryAllocatedByTestImportImageContainer{ false };
};

class ImportImageContainerFactory : public itk::ObjectFactoryBase
Expand Down