9#include <QGlobalStatic>
10#include <QMutexLocker>
37struct DefaultMemoryAllocatorStore {
38 static DefaultMemoryAllocatorStore*
instance();
40 DefaultMemoryAllocatorStore()
41 : m_allocator(new DefaultMemoryAllocator())
55DefaultMemoryAllocatorStore *DefaultMemoryAllocatorStore::instance()
85 QMutexLocker l(&m_mutex);
86 if (!m_chunks.isEmpty()) {
87 chunk = m_chunks.takeLast();
93 if (chunk.second <
size) {
98 const int allocSize = 1.2 *
size;
108 QMutexLocker l(&m_mutex);
112 if (chunk.second > 0.8 * m_meanSize.rollingMean()) {
113 m_chunks.append(chunk);
115 delete[] chunk.first;
130 _allocator ? _allocator : DefaultMemoryAllocatorStore::instance()->allocator();
199 if (
size ==
m_d->dataSize)
return;
202 m_d->allocator->free(
m_d->data);
216 return m_d->dataSize;
221 return !
m_d->dataSize;
226 return m_d->storedAllocator;
float value(const T *src, size_t ch)
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
PythonPluginManager * instance
std::pair< quint8 *, int > MemoryChunk
const quint8 * constData() const
QSharedDataPointer< Private > m_d
KisOptimizedByteArray & operator=(const KisOptimizedByteArray &rhs)
KisOptimizedByteArray(MemoryAllocatorSP allocator=MemoryAllocatorSP())
void fill(quint8 value, int size=-1)
MemoryAllocatorSP customMemoryAllocator() const
virtual void free(MemoryChunk chunk)=0
virtual MemoryChunk alloc(int size)=0
void free(MemoryChunk chunk) override
MemoryChunk alloc(int size) override
MemoryAllocatorSP storedAllocator
MemoryAllocator * allocator
Private(const Private &rhs)
Private(MemoryAllocatorSP _allocator)