Loading...
Searching...
No Matches
juce_ArrayAllocationBase.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
template <class ElementType, class TypeOfCriticalSectionToUse>
class ArrayAllocationBase : public TypeOfCriticalSectionToUse
{
public:
//==============================================================================
ArrayAllocationBase() = default;
~ArrayAllocationBase() = default;
ArrayAllocationBase (ArrayAllocationBase&& other) noexcept
: elements (std::move (other.elements)),
numAllocated (other.numAllocated)
{
}
ArrayAllocationBase& operator= (ArrayAllocationBase&& other) noexcept
{
elements = std::move (other.elements);
numAllocated = other.numAllocated;
return *this;
}
//==============================================================================
void setAllocatedSize (int numElements)
{
if (numAllocated != numElements)
{
if (numElements > 0)
elements.realloc ((size_t) numElements);
else
elements.free();
numAllocated = numElements;
}
}
void ensureAllocatedSize (int minNumElements)
{
if (minNumElements > numAllocated)
setAllocatedSize ((minNumElements + minNumElements / 2 + 8) & ~7);
jassert (numAllocated <= 0 || elements != nullptr);
}
void shrinkToNoMoreThan (int maxNumElements)
{
if (maxNumElements < numAllocated)
setAllocatedSize (maxNumElements);
}
void swapWith (ArrayAllocationBase& other) noexcept
{
elements.swapWith (other.elements);
std::swap (numAllocated, other.numAllocated);
}
//==============================================================================
HeapBlock<ElementType> elements;
int numAllocated = 0;
private:
JUCE_DECLARE_NON_COPYABLE (ArrayAllocationBase)
};
} // namespace juce
juce::ArrayAllocationBase
Definition juce_ArrayAllocationBase.h:38
juce::ArrayAllocationBase::shrinkToNoMoreThan
void shrinkToNoMoreThan(int maxNumElements)
Definition juce_ArrayAllocationBase.h:100
juce::ArrayAllocationBase::ArrayAllocationBase
ArrayAllocationBase()=default
juce::ArrayAllocationBase::~ArrayAllocationBase
~ArrayAllocationBase()=default
juce::ArrayAllocationBase::ensureAllocatedSize
void ensureAllocatedSize(int minNumElements)
Definition juce_ArrayAllocationBase.h:89
juce::ArrayAllocationBase::setAllocatedSize
void setAllocatedSize(int numElements)
Definition juce_ArrayAllocationBase.h:68
juce::ArrayAllocationBase::swapWith
void swapWith(ArrayAllocationBase &other) noexcept
Definition juce_ArrayAllocationBase.h:107
juce::HeapBlock
Definition juce_HeapBlock.h:87