TunedMemory Class Reference

This is a shell around the CCMalloc and CCFree memory allocator. If you use this class to get the memory, the total alloc'ed memory will not exceed the amount set in this class. This is used to allow the user to say how much memory they are prepared to commit to the off-screen bitmap used in rendering. If there is not enough, GRenderRegions will band thier output to use up less ram. More...

#include <tunemem.h>

List of all members.

Public Member Functions

 TunedMemory ()
 Constructor - sets the memory thing up with a default value of 1Mb of available ram.
 ~TunedMemory ()
 Destructor - TRACES an error out if there is still some ram left over.
LPVOID LimitedCCMalloc (size_t Size)
 Allocates ram out of the limited pool. The Available ram is decreased.
LPVOID LimitedCCRealloc (LPVOID buf, size_t NewSize)
 Re-Allocates ram out of the limited pool. The Available ram is decreased.
void LimitedCCFree (LPVOID buf)
 Frees the memory allocated by LimitedCCMalloc.
size_t GetTotalTunedMem ()
 Finds out the total ram that can be allocated in the limited memory thing. This is how much ram the user has deemed enough for Camelot to do its rendering etc with. When this ammount has been allocated rendering will have to wait for other regions to finish before they can start.
size_t GetAvailableTunedMem ()
 This is the amount of the ram that could be allocated (GetTotal) that is still left unallocated. If this amount is not enough for your job, then you should wait until this function returns a bigger number. It would also be worth checking to see if the TotalTunedRam would be enough as well.

Static Public Member Functions

static size_t GetLimitedMemSize ()
 To allows the Options Dialog to find out what the current setting for the amount of RAM that can be used for rendering is at.
static size_t SetLimitedMemSize (size_t NewSize)
 This function allows the options dialog to set the amount of ram to use for drawing to a new value that the user chose. If the value is less than a minimum useful value, at present 128k, then the value will be ignored and 128k will be used.
static BOOL IsMemSizeInfinite ()
 Lets the options dialog have a look at the Tuned Memorys IsInfinite state.
static void SetMemSizeInfinte (BOOL NewIsInfinite)
 Sets the infinte flag in the limited memory manager. TRUE means the limited heap should be made infinte, FALSE means use the value found by GetLimitedMemSize NOTE: This call now determines whether to use the recommended memory or not.
static INT32 GetScreenMemSize ()
 This function gives a figure for the amount of ram needed to redraw the full screen with transparency on. for 1024 x 768 this is about 3.5Meg.
static BOOL IsAutomaticMemory ()
 Lets the options dialog have a look at the Smart banding state.
static void CalculateRecommendedMemory ()
 Calculates a sensible default Banding size given the Physical memory available.
static BOOL Init ()
 Declares the preferences for this class in the ini file.

Static Protected Attributes

static BOOL IsInfinite = TRUE
 If this pref is TRUE then the MaxRenderingRAM preference is ignored and all the ram we want is used. If it is FALSE the rendering ram will be limited to the figure in MaxRenderingRAM.
static size_t TotalRAM = 1024*768
static size_t AvailableRAM = 1024*768
static BOOL SmartBanding = TRUE
 If this pref is TRUE then the MaxRenderingRAM preference is ignored and the amount to use is calculated according to available memory. If it is FALSE the rendering ram will be limited to the figure in MaxRenderingRAM.
static size_t LimitRAM = 1024*768
 This pref is used to set the maximum amount of ram that can be used to render with. If there is less than the screen needs here, the rendering will be banded. Useful on Low memory machines.
static BOOL RecommendInfinite = FALSE
static INT32 RecommendRAM = 1024*768

Private Member Functions

 CC_DECLARE_MEMDUMP (TunedMemory)


Detailed Description

This is a shell around the CCMalloc and CCFree memory allocator. If you use this class to get the memory, the total alloc'ed memory will not exceed the amount set in this class. This is used to allow the user to say how much memory they are prepared to commit to the off-screen bitmap used in rendering. If there is not enough, GRenderRegions will band thier output to use up less ram.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95

Definition at line 119 of file tunemem.h.


Constructor & Destructor Documentation

TunedMemory::TunedMemory  ) 
 

Constructor - sets the memory thing up with a default value of 1Mb of available ram.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95

Definition at line 179 of file tunemem.cpp.

00180 {
00181     // make sure that the available ram is the same as the total
00182     AvailableRAM = TotalRAM = LimitRAM;
00183 }

TunedMemory::~TunedMemory  ) 
 

Destructor - TRACES an error out if there is still some ram left over.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95

Definition at line 199 of file tunemem.cpp.

00200 {
00201     if (AvailableRAM!=TotalRAM)
00202     {
00203         TRACEUSER( "Rik", wxT("At Exit the Available Ram did not equal the Total Ram in TunedMemory\n") );
00204         TRACEUSER( "Rik", wxT("TotalRAM = %ld, Available=%ld\n"), TotalRAM, AvailableRAM );
00205     }
00206 }


Member Function Documentation

void TunedMemory::CalculateRecommendedMemory  )  [static]
 

Calculates a sensible default Banding size given the Physical memory available.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/6/95

Definition at line 567 of file tunemem.cpp.

00568 {
00569     TRACE( _T("Warning - TunedMemory::CalculateRecommendedMemory called") );
00570 
00571 #if defined(__WXMSW)
00572     MEMORYSTATUS MemStat;
00573     MemStat.dwLength = sizeof(MEMORYSTATUS);
00574     GlobalMemoryStatus(&MemStat);
00575 
00576     INT32 PhysicalMemory = MemStat.dwTotalPhys;
00577     TRACEALL( wxT("Total Physical Memory is %d\n"), PhysicalMemory);
00578 
00579 //  INT32 ScreenMem = GetScreenMemSize();
00580 //  TRACEALL( _T("Screen Memory is %d\n"), ScreenMem);
00581 
00582     if (PhysicalMemory <= 8*1024*1024)          // 8 Megs or less
00583     {
00584         RecommendInfinite = FALSE;              // Use limited memory
00585         RecommendRAM = 512*1024;                // Limit to max of 512 K
00586     }
00587     else if (PhysicalMemory <= 12*1024*1024)    // 8 to 12 Megs
00588     {
00589         RecommendInfinite = FALSE;              // Use limited memory
00590         RecommendRAM = 1*1024*1024;             // Limit to max of 1024 K
00591     }
00592     else if (PhysicalMemory <= 16*1024*1024)    // 12 to 16 Megs
00593     {
00594         RecommendInfinite = FALSE;              // Use limited memory
00595         RecommendRAM = 2*1024*1024;             // Limit to max of 2048 K
00596     }
00597     else                                        // More than 16 Megs
00598     {
00599         RecommendInfinite = TRUE;               // Unlimited memory
00600     }
00601 
00602     if (ShowBandingRAM)
00603     {
00604         ERROR3_PF( ("Total Physical Memory is %d", PhysicalMemory) );
00605 
00606         if (IsInfinite)
00607         {
00608             ERROR3("Using unlimited banding RAM");
00609             TRACEALL( wxT("Using unlimited Rendering RAM\n") );
00610         }
00611         else
00612         {
00613             ERROR3_PF( ("Rendering RAM set to %d",TotalRAM) );
00614             TRACEALL( wxT("Rendering RAM set to %d\n"), TotalRAM );
00615         }
00616     }
00617 #else
00618     RecommendInfinite = TRUE;
00619 #endif
00620 }

TunedMemory::CC_DECLARE_MEMDUMP TunedMemory   )  [private]
 

size_t TunedMemory::GetAvailableTunedMem  ) 
 

This is the amount of the ram that could be allocated (GetTotal) that is still left unallocated. If this amount is not enough for your job, then you should wait until this function returns a bigger number. It would also be worth checking to see if the TotalTunedRam would be enough as well.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95
Returns:
The amount of available ram in the limited pool

Definition at line 341 of file tunemem.cpp.

00342 {
00343     return AvailableRAM;
00344 }

size_t TunedMemory::GetLimitedMemSize  )  [static]
 

To allows the Options Dialog to find out what the current setting for the amount of RAM that can be used for rendering is at.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/5/95
Returns:
The current size of the limited memory thing

Definition at line 360 of file tunemem.cpp.

00361 {
00362     return LimitRAM;
00363 }

INT32 TunedMemory::GetScreenMemSize  )  [static]
 

This function gives a figure for the amount of ram needed to redraw the full screen with transparency on. for 1024 x 768 this is about 3.5Meg.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/5/95
Returns:
The mem required to do a full screen redraw with transparancy on

Definition at line 503 of file tunemem.cpp.

00504 {
00505     INT32                   Width  = wxSystemSettings::GetMetric( wxSYS_SCREEN_X );
00506     INT32                   Height = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
00507     return Width * Height * 4;
00508 }

size_t TunedMemory::GetTotalTunedMem  ) 
 

Finds out the total ram that can be allocated in the limited memory thing. This is how much ram the user has deemed enough for Camelot to do its rendering etc with. When this ammount has been allocated rendering will have to wait for other regions to finish before they can start.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95
Returns:
Total ram in the limited heap
See also:
TunedMemory::GetAvailableTunedMem

Definition at line 318 of file tunemem.cpp.

00319 {
00320     return TotalRAM;
00321 }

BOOL TunedMemory::Init void   )  [static]
 

Declares the preferences for this class in the ini file.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/5/95
Returns:
TRUE if it worked, FALSE if not

Definition at line 524 of file tunemem.cpp.

00525 {
00526     if( Camelot.DeclareSection( wxT("Screen"), 10 ) )
00527     { 
00528         Camelot.DeclarePref( NULL, wxT("MaxRenderingRAM"), (INT32*)&LimitRAM );
00529         Camelot.DeclarePref( NULL, wxT("IsRenderingRAMInfinte"), &IsInfinite, FALSE, TRUE );
00530         Camelot.DeclarePref( NULL, wxT("SmartRenderingRAM"), &SmartBanding, FALSE, TRUE );
00531 
00532 //      Camelot.DeclarePref(NULL, "ShowBandingRAM", &ShowBandingRAM, FALSE, TRUE);
00533     }
00534 
00535     // Find the available Physical memory,
00536     // and work out a sensible band size to use
00537     CalculateRecommendedMemory();
00538 
00539     if (SmartBanding)
00540     {
00541         // Use the recommended memory
00542         TotalRAM    = RecommendRAM;
00543         IsInfinite  = RecommendInfinite;
00544     }
00545     else
00546     {
00547         // Use the user specified limited RAM
00548         TotalRAM    = LimitRAM;
00549     }
00550 
00551     // Set available ram equal to the total ram
00552     AvailableRAM = TotalRAM;
00553     return TRUE;
00554 }

BOOL TunedMemory::IsAutomaticMemory  )  [static]
 

Lets the options dialog have a look at the Smart banding state.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/6/95
Returns:
TRUE if the memory limit will be calculated automatically. FALSE if the user value is being used.

Definition at line 431 of file tunemem.cpp.

00432 {
00433     // This routine has been changed to determine whether to use the
00434     // recommended memory or not.
00435     return SmartBanding;
00436 }

BOOL TunedMemory::IsMemSizeInfinite  )  [static]
 

Lets the options dialog have a look at the Tuned Memorys IsInfinite state.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/5/95
Returns:
TRUE if the Limited heap is not currently limited, FALSE if it is

Definition at line 414 of file tunemem.cpp.

00415 {
00416     return IsInfinite;
00417 }

void TunedMemory::LimitedCCFree LPVOID  buf  ) 
 

Frees the memory allocated by LimitedCCMalloc.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95
Parameters:
buf - the previously allocated buffer [INPUTS]

Definition at line 286 of file tunemem.cpp.

00287 {
00288     // Find out how big the block was
00289     size_t BlockSize = CCGetBlockSize(buf); 
00290 
00291     // add it back into the pool
00292     if (!IsInfinite)
00293         AvailableRAM += BlockSize;
00294 
00295     // Free the memory
00296     CCFree(buf);
00297 }

LPVOID TunedMemory::LimitedCCMalloc size_t  Size  ) 
 

Allocates ram out of the limited pool. The Available ram is decreased.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/5/95
Parameters:
Size - the ammount of ram needed [INPUTS]
Returns:
A pointer to the allocated ram or NULL if there is no more ram available
See also:
LimitedCCFree

Definition at line 225 of file tunemem.cpp.

00226 {
00227     // Get some ram
00228     LPVOID Memory = CCMalloc(Size);
00229 
00230     // if we got it, make a note of its allocation
00231     if ((Memory!=NULL) && (!IsInfinite))
00232     {
00233         AvailableRAM -= Size;
00234     }
00235 
00236     // return what we got
00237     return Memory;
00238 }

LPVOID TunedMemory::LimitedCCRealloc LPVOID  buf,
size_t  NewSize
 

Re-Allocates ram out of the limited pool. The Available ram is decreased.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/7/95
Parameters:
Size - the new ammount of ram needed [INPUTS]
Returns:
A pointer to the allocated ram or NULL if there is no more ram available
See also:
LimitedCCFree

Definition at line 253 of file tunemem.cpp.

00254 {
00255     // Find out how big the block is at the moment
00256     size_t OldSize = CCGetBlockSize(buf); 
00257 
00258     // Resize the block
00259     LPVOID Memory = CCRealloc( buf, NewSize );
00260 
00261     // If it got bigger, then decrease the available RAM,
00262     // otherwise we increase it
00263     if ((Memory!=NULL) && (!IsInfinite))
00264     {
00265         AvailableRAM -= (NewSize - OldSize);
00266     }
00267 
00268     // return what we got
00269     return Memory;
00270 }

size_t TunedMemory::SetLimitedMemSize size_t  NewSize  )  [static]
 

This function allows the options dialog to set the amount of ram to use for drawing to a new value that the user chose. If the value is less than a minimum useful value, at present 128k, then the value will be ignored and 128k will be used.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/5/95
Parameters:
NewSize - The new size of the limited memory heap [INPUTS]
Returns:
NewSize if ok or if the value is too low, a new minimum size.

Definition at line 382 of file tunemem.cpp.

00383 {
00384     // make sure it is not too small for safty
00385     if (NewSize<1024*128)
00386         NewSize = 1024*128;
00387 
00388     // Find out what the difference is
00389     size_t Difference = NewSize - TotalRAM;
00390 
00391     // Set the total to the new size
00392     TotalRAM = NewSize;
00393     LimitRAM = NewSize;
00394 
00395     // And change the available ram as well
00396     AvailableRAM += Difference;
00397     
00398     return NewSize;
00399 }

void TunedMemory::SetMemSizeInfinte BOOL  NewSmartBanding  )  [static]
 

Sets the infinte flag in the limited memory manager. TRUE means the limited heap should be made infinte, FALSE means use the value found by GetLimitedMemSize NOTE: This call now determines whether to use the recommended memory or not.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/5/95
Parameters:
NewIsInfinite - The new state of the Infinte flag [INPUTS]

Definition at line 454 of file tunemem.cpp.

00455 {
00456     // Set the member version
00457     SmartBanding = NewSmartBanding;
00458 
00459     if (SmartBanding)
00460     {
00461         // If 'Smart' banding enabled, then use the 
00462         // recommended memory (calculated on startup)
00463         IsInfinite  = RecommendInfinite;
00464 
00465         if (!IsInfinite)
00466         {
00467             // Set the recommended memory limit
00468 
00469             // Find out what the difference is
00470             size_t      Difference = RecommendRAM - TotalRAM;
00471 
00472             // Set the total to the new size
00473             TotalRAM = RecommendRAM;
00474 
00475             // And change the available ram as well
00476             AvailableRAM += Difference;
00477         }
00478     }
00479     else
00480     {
00481         // Use the user specified limited RAM
00482         IsInfinite = FALSE;
00483         TotalRAM = LimitRAM;
00484         AvailableRAM = LimitRAM;
00485     }
00486 }


Member Data Documentation

size_t TunedMemory::AvailableRAM = 1024*768 [static, protected]
 

Definition at line 158 of file tunemem.h.

BOOL TunedMemory::IsInfinite = TRUE [static, protected]
 

If this pref is TRUE then the MaxRenderingRAM preference is ignored and all the ram we want is used. If it is FALSE the rendering ram will be limited to the figure in MaxRenderingRAM.

Preference: IsRenderingRAMInfinte Section: Range: TRUE, FALSE

Definition at line 156 of file tunemem.h.

size_t TunedMemory::LimitRAM = 1024*768 [static, protected]
 

This pref is used to set the maximum amount of ram that can be used to render with. If there is less than the screen needs here, the rendering will be banded. Useful on Low memory machines.

Preference: MaxRenderingRAM Section: Range: >128K

Definition at line 162 of file tunemem.h.

BOOL TunedMemory::RecommendInfinite = FALSE [static, protected]
 

Definition at line 163 of file tunemem.h.

INT32 TunedMemory::RecommendRAM = 1024*768 [static, protected]
 

Definition at line 164 of file tunemem.h.

BOOL TunedMemory::SmartBanding = TRUE [static, protected]
 

If this pref is TRUE then the MaxRenderingRAM preference is ignored and the amount to use is calculated according to available memory. If it is FALSE the rendering ram will be limited to the figure in MaxRenderingRAM.

Preference: SmartRenderingRAM Section: Range: TRUE, FALSE

Definition at line 160 of file tunemem.h.

size_t TunedMemory::TotalRAM = 1024*768 [static, protected]
 

Definition at line 157 of file tunemem.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 04:02:29 2007 for Camelot by  doxygen 1.4.4