webengine/osswebengine/MemoryManager/Src/MemoryManager.cpp
changeset 36 0ed94ceaa377
parent 13 10e98eab6f85
child 37 cb62a4f66ebe
--- a/webengine/osswebengine/MemoryManager/Src/MemoryManager.cpp	Tue Nov 24 09:02:20 2009 +0200
+++ b/webengine/osswebengine/MemoryManager/Src/MemoryManager.cpp	Thu Dec 17 09:20:16 2009 +0200
@@ -21,6 +21,7 @@
 #include "MemoryManager.h"
 #include "MemoryPool.h"
 #include "FastAllocator.h"
+#include "MemoryLogger.h"
 
 // CONSTANTS
 
@@ -58,16 +59,50 @@
     }
 
 //-----------------------------------------------------------------------------
+// MemoryManager::CreateAllocator
+//-----------------------------------------------------------------------------
+EXPORT_C void MemoryManager::CreateFastAllocator()
+    {
+    // create the right memory pool
+    MEM_LOGF(_L8("MemoryManager::CreateFastAllocator - s_pool=%x"), s_pool);
+#ifdef __NEW_ALLOCATOR__
+    CMemoryPool *pool = new CNewSymbianHeapPool();
+    pool->Create();
+    RSymbianDlAllocatorWrapper* allocator = new RSymbianDlAllocatorWrapper((CNewSymbianHeapPool*)pool);
+    MEM_LOGF(_L8("MemoryManager::CreateFastAllocator - new pool=%x, allocator=%x"), pool, allocator);
+    User::SwitchAllocator(allocator);
+#endif
+    }
+
+//-----------------------------------------------------------------------------
+// MemoryManager::InitAllocator
+//-----------------------------------------------------------------------------
+EXPORT_C void MemoryManager::InitFastAllocator()
+    {
+    // Initialize s_pool variable from current allocator, assumption is that main program has already called CreateAllocator()
+    // It is special case when this allocator is created in SetupThreadHeap() where can not initialize static data. It also
+    // solves problems due to static data destruction in Symbian 9.5.
+#ifdef __NEW_ALLOCATOR__    
+    RAllocator &aAllocator = User::Allocator();
+    RSymbianDlAllocatorWrapper* allocator = (RSymbianDlAllocatorWrapper*) &aAllocator;
+    s_pool = allocator->iPool;
+    MEM_LOGF(_L8("MemoryManager::InitFastAllocator - s_pool=%x, allocator=%x"), s_pool, allocator);
+#endif    
+    }
+
+//-----------------------------------------------------------------------------
 // MemoryManager::SwitchToFastAllocator
 //-----------------------------------------------------------------------------
 EXPORT_C RAllocator* MemoryManager::SwitchToFastAllocator()
     {
     // create the right memory pool
-    __ASSERT_DEBUG( s_pool == 0, User::Panic( KMemManPanicDes, 0 ) );
+    //__ASSERT_DEBUG( s_pool == 0, User::Panic( KMemManPanicDes, 0 ) );
+    MEM_LOGF(_L8("MemoryManager::SwitchToFastAllocator - s_pool=%x"), s_pool);
 #ifdef __NEW_ALLOCATOR__
     s_pool = new CNewSymbianHeapPool();
     s_pool->Create();
     RSymbianDlAllocatorWrapper* allocator = new RSymbianDlAllocatorWrapper((CNewSymbianHeapPool*)s_pool);
+    MEM_LOGF(_L8("MemoryManager::SwitchToFastAllocator - new s_pool=%x"), s_pool);
     return User::SwitchAllocator( allocator );
 #else
     s_pool = new CFastMemoryPool();
@@ -96,6 +131,7 @@
 //-----------------------------------------------------------------------------
 EXPORT_C void MemoryManager::AddCollector( MMemoryCollector* aCollector )
     {
+    MEM_LOGF(_L8("MemoryManager::AddCollector - s_pool=%x"), s_pool);
     Pool()->AddCollector( aCollector );
     }
 
@@ -112,6 +148,7 @@
 //-----------------------------------------------------------------------------
 EXPORT_C void MemoryManager::AddStopper( MOOMStopper* aStopper )
     {
+    MEM_LOGF(_L8("MemoryManager::AddStopper - s_pool=%x"), s_pool);
     Pool()->AddStopper( aStopper );
     }