widgets/widgetapp/src/WidgetUiApp.cpp
changeset 36 0ed94ceaa377
parent 0 dd21522fd290
child 37 cb62a4f66ebe
--- a/widgets/widgetapp/src/WidgetUiApp.cpp	Tue Nov 24 09:02:20 2009 +0200
+++ b/widgets/widgetapp/src/WidgetUiApp.cpp	Thu Dec 17 09:20:16 2009 +0200
@@ -15,12 +15,12 @@
 *
 */
 
-
 #include    "WidgetUiApp.h"
 #include    "WidgetUiDocument.h"
 #include    "MemoryManager.h"
 #include    "widgetappdefs.rh"
 #include    <eikstart.h>
+#include <u32std.h>
 
 // EXTERNAL DATA STRUCTURES
 
@@ -88,18 +88,48 @@
     }
 
 // -----------------------------------------------------------------------------
+// SetupThreadHeap - Called for heap creation of thread in this process.
+// This approach used to keep correct heap for pointers held in static data objects
+// when they are destructed after E32Main() by OS.
+// -----------------------------------------------------------------------------
+//
+EXPORT_C TInt UserHeap::SetupThreadHeap(TBool aSubThread, SStdEpocThreadCreateInfo& aInfo)
+    {
+    TInt r = KErrNone;
+    if (!aInfo.iAllocator && aInfo.iHeapInitialSize>0)
+        {
+        // new heap required
+        RHeap* pH = NULL;
+        r = CreateThreadHeap(aInfo, pH);
+        if (r == KErrNone && !aSubThread)
+            {
+            // main thread - new allocator created and set as default heap      
+            MemoryManager::CreateFastAllocator();
+            }
+        }
+    else if (aInfo.iAllocator)
+        {
+        // sharing a heap
+        RAllocator* pA = aInfo.iAllocator;
+        pA->Open();
+        User::SwitchAllocator(pA);
+        }
+
+    return r;
+    }
+    
+    
+// -----------------------------------------------------------------------------
 // E32Main
 //
 // -----------------------------------------------------------------------------
 //
 GLDEF_C TInt E32Main()
     {
-    RAllocator* oldAllocator = MemoryManager::SwitchToFastAllocator();
-    __UHEAP_MARK;
-    TInt result = EikStart::RunApplication( NewApplication );
-    __UHEAP_MARKEND;
-    MemoryManager::CloseFastAllocator(oldAllocator);
-    return result;
+        // initialize MemmoryManager
+        MemoryManager::InitFastAllocator();    
+        
+    	return EikStart::RunApplication(NewApplication); 
     }
-
+        
 // End of File