Changing and fixing some stuff

- QHash is better to use than QMap in MemoryManager: faster lookups, able to reserve memory in advance
- Also: reserve memory in advance for the QVector and QHash, so we don't get needles allocs for them
- No need to do cleanup for the nph manager, as it uses the generic manager for allocs, and that already gets cleaned up
This commit is contained in:
Vesa
2014-08-24 13:38:48 +03:00
parent 42e67d27a1
commit 8fb8c683f9
5 changed files with 4 additions and 13 deletions

View File

@@ -29,7 +29,7 @@
#include <new>
#include <QtCore/QVector>
#include <QtCore/QMutex>
#include <QtCore/QMap>
#include <QtCore/QHash>
#include "MemoryHelper.h"
@@ -83,7 +83,7 @@ struct PtrInfo
};
typedef QVector<MemoryPool> MemoryPoolVector;
typedef QMap<void*, PtrInfo> PointerInfoMap;
typedef QHash<void*, PtrInfo> PointerInfoMap;
class MemoryManager
{

View File

@@ -330,7 +330,6 @@ public:
NotePlayHandle::Origin origin = NotePlayHandle::OriginPattern );
static void release( NotePlayHandle * nph );
static void extend( int i );
static void cleanup();
private:
static NotePlayHandleList s_nphCache;

View File

@@ -37,6 +37,8 @@ QMutex MemoryManager::s_pointerMutex;
bool MemoryManager::init()
{
s_memoryPools.reserve( 64 );
s_pointerInfo.reserve( 4096 );
// construct first MemoryPool and allocate memory
MemoryPool m ( MM_INITIAL_CHUNKS );
m.m_pool = MemoryHelper::alignedMalloc( MM_INITIAL_CHUNKS * MM_CHUNK_SIZE );

View File

@@ -612,12 +612,3 @@ void NotePlayHandleManager::extend( int i )
}
s_mutex.unlock();
}
void NotePlayHandleManager::cleanup()
{
foreach( NotePlayHandle * n, s_nphCache )
{
delete n;
}
}

View File

@@ -538,7 +538,6 @@ int main( int argc, char * * argv )
// cleanup memory managers
MemoryManager::cleanup();
NotePlayHandleManager::cleanup();
return( ret );
}