459 //----------------------------------------------------------------------------- |
463 //----------------------------------------------------------------------------- |
460 // CNewSymbianHeapPool::DoAlloc |
464 // CNewSymbianHeapPool::DoAlloc |
461 //----------------------------------------------------------------------------- |
465 //----------------------------------------------------------------------------- |
462 TAny* CNewSymbianHeapPool::DoAlloc( TUint aSize ) |
466 TAny* CNewSymbianHeapPool::DoAlloc( TUint aSize ) |
463 { |
467 { |
464 return iAlloc->Alloc( aSize ); |
468 TAny *p = iAlloc->Alloc( aSize ); |
|
469 if (!p) |
|
470 ShowOOMDialog(); |
|
471 return p; |
465 } |
472 } |
466 |
473 |
467 //----------------------------------------------------------------------------- |
474 //----------------------------------------------------------------------------- |
468 // CNewSymbianHeapPool::ReAllocate |
475 // CNewSymbianHeapPool::ReAllocate |
469 //----------------------------------------------------------------------------- |
476 //----------------------------------------------------------------------------- |
549 req = freeSpace + systemFreeMemory - aTotalSize; |
557 req = freeSpace + systemFreeMemory - aTotalSize; |
550 |
558 |
551 if(req > 0) |
559 if(req > 0) |
552 return ETrue; |
560 return ETrue; |
553 |
561 |
554 // We haven't got the required amount free yet, try the browser heap. |
562 // We haven't got the required amount free yet, pop an OOM dialog and then try the browser heap. |
|
563 ShowOOMDialog(); |
555 CollectMemory(aTotalSize); |
564 CollectMemory(aTotalSize); |
556 // ask the system how much is free now... |
565 // ask the system how much is free now... |
557 HAL::Get(HALData::EMemoryRAMFree, systemFreeMemory); |
566 HAL::Get(HALData::EMemoryRAMFree, systemFreeMemory); |
558 req = freeSpace + systemFreeMemory - aTotalSize; |
567 req = freeSpace + systemFreeMemory - aTotalSize; |
559 |
568 |
608 //alloc_rescue_buffer(); |
617 //alloc_rescue_buffer(); |
609 } |
618 } |
610 |
619 |
611 CNewSymbianHeapPool::CNewSymbianHeapPool() : CMemoryPool() |
620 CNewSymbianHeapPool::CNewSymbianHeapPool() : CMemoryPool() |
612 { |
621 { |
|
622 isInitted = EFalse; |
|
623 iOOMErrorDialog = 0; |
|
624 iOOMMessage = 0; |
613 } |
625 } |
614 |
626 |
615 CNewSymbianHeapPool::~CNewSymbianHeapPool() |
627 CNewSymbianHeapPool::~CNewSymbianHeapPool() |
616 { |
628 { |
617 // iAlloc->Close(); // TODO: Need to clean up here, but it's not implemented in the allocator yet. |
629 // iAlloc->Close(); // TODO: Need to clean up here, but it's not implemented in the allocator yet. |
661 return EFalse; |
673 return EFalse; |
662 |
674 |
663 return CMemoryPool::Create(); |
675 return CMemoryPool::Create(); |
664 } |
676 } |
665 |
677 |
|
678 /* |
|
679 * Initialize the OOM dialog and localized message resource |
|
680 * This should be called as soon in the startup process as possible |
|
681 * (unfortunately it can't be called until resources are already loaded) |
|
682 * Note: apps are responsible for showing their own oom dialog; there |
|
683 * is no system one AFAIK; at least we can re-use the oom localized |
|
684 * resource message from elsewhere |
|
685 */ |
|
686 void CNewSymbianHeapPool::InitOOMDialog() |
|
687 { |
|
688 if (!isInitted) |
|
689 { |
|
690 isInitted = ETrue; |
|
691 iOOMErrorDialog = CAknGlobalNote::NewL(); |
|
692 iOOMErrorDialog->SetSoftkeys(R_AVKON_SOFTKEYS_OK_EMPTY); |
|
693 iOOMMessage = StringLoader::LoadL(R_QTN_BROWSER_DIALOG_OOM); |
|
694 iOOMDisplayed = EFalse; |
|
695 } |
|
696 } |
|
697 |
|
698 void CNewSymbianHeapPool::ShowOOMDialog() |
|
699 { |
|
700 // Don't show it if we did once already |
|
701 if (iOOMDisplayed) |
|
702 return; |
|
703 |
|
704 // If we got OOM, show a dialog (if the dialog was initted properly to begin with) |
|
705 if (iOOMErrorDialog) |
|
706 { |
|
707 // If we couldn't load the message resource when we first initted, |
|
708 // try again now; this shouldn't ever happen |
|
709 if (!iOOMMessage) |
|
710 { |
|
711 iOOMMessage = StringLoader::LoadL(R_QTN_BROWSER_DIALOG_OOM); |
|
712 } |
|
713 // If we have no dialog or message we unfortunately cannot display it! |
|
714 if (iOOMMessage) |
|
715 { |
|
716 iOOMErrorDialog->ShowNoteL(EAknGlobalWarningNote,iOOMMessage->Des()); |
|
717 iOOMDisplayed = ETrue; |
|
718 } |
|
719 } |
|
720 } |
|
721 |
|
722 void CNewSymbianHeapPool::ResetOOMDialogDisplayed() |
|
723 { |
|
724 iOOMDisplayed = EFalse; |
|
725 } |
|
726 |
666 #ifdef OOM_LOGGING |
727 #ifdef OOM_LOGGING |
667 void CNewSymbianHeapPool::DumpHeapLogs() |
728 void CNewSymbianHeapPool::DumpHeapLogs() |
668 { |
729 { |
669 iAlloc->dump_heap_logs(0); |
730 iAlloc->dump_heap_logs(0); |
670 iAlloc->dump_dl_free_chunks(); |
731 iAlloc->dump_dl_free_chunks(); |