home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TPoolNotifierExample.h
-
- Contains: The Shared Library Manager provides the TPoolNotifier class to assist
- in automatically “growing” a pool when the pool comes dangerously close
- to running out of memory. This is an example of TPoolNotifier.
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __TPOOLNOTIFIEREXAMPLE__
- #define __TPOOLNOTIFIEREXAMPLE__
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// TMyPoolNotifier
- ///
- /// This is a TPoolNotifier subclass that overrides the Notify and GrowBy routines
- /// simply for the sake of displaying a message.
- ///————————————————————————————————————————————————————————————————————————————————————
-
- class TMyPoolNotifier : public TPoolNotifier {
- public:
- TMyPoolNotifier(unsigned short growBy = 10,
- unsigned short minGrow = 128);
- virtual ~TMyPoolNotifier();
-
- // TPoolNotifier methods that we override
- virtual void Notify( EventCode, OSErrParm = kNoError, void *theData=NULL );
- virtual size_t GrowBy( TMemoryPool*, size_t );
-
- private:
- GlobalWorld fWorld; // so we can setup our world when called at system task time
- };
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// TMyPoolNotifier IMPLEMENTATION
- ///————————————————————————————————————————————————————————————————————————————————————
-
- TMyPoolNotifier::TMyPoolNotifier(unsigned short growBy, unsigned short minGrow) :
- TPoolNotifier( growBy , minGrow )
- {
- fWorld = GetCurrentGlobalWorld();
- }
-
- TMyPoolNotifier::~TMyPoolNotifier()
- {
- }
-
- /// notify the user when we reached the low and high marks
-
- void TMyPoolNotifier::Notify( EventCode evtCode, OSErrParm err, void *thePool )
- {
- GlobalWorld savedWorld = SetCurrentGlobalWorld(fWorld);
-
- cout << "TMyPoolNotifier::Notify called: ";
- cout << "thePool = " << (void*)thePool << endl;
-
- if( evtCode == kLowPoolMemoryEvent )
- cout << "Reached LOW MEMORY indicator" << endl;
- else
- cout << "Reached HIGH MEMORY indicator" << endl;
-
- TPoolNotifier::Notify( evtCode, err, thePool ); // call the default
-
- SetCurrentGlobalWorld(savedWorld);
- }
-
- size_t TMyPoolNotifier::GrowBy( TMemoryPool* thePool, size_t theSize)
- {
- GlobalWorld savedWorld = SetCurrentGlobalWorld(fWorld);
-
- cout << "TMyPoolNotifier::GrowBy called: ";
- cout << "thePool = " << (void*)thePool << " theSize = " << theSize << endl;
-
- SetCurrentGlobalWorld(savedWorld);
-
- return TPoolNotifier::GrowBy( thePool, theSize ); // call the default
- }
-
- #endif