Manage global buffer cache

Web Site  Methods

Str has a mechanism to cache the last few used memory blocks (buffers), instead of returning them to the underlying OS. This is done only for blocks under a certain size (defined with STR_DITEMS) and if the caching mechanism is not disabled completely with STR_NO_BLOCK_CACHE.

The two static methods described here manipulate this buffer cache mechanism.

 

 
Str::CompactFreeMemory
 
static void CompactFreeMemory ()

Calling this static method will release all currently cached blocks to the underlying OS.  However, the next time Str uses a memory block and tries to return it, the block will be returned to the cache again.

There is an important performance consideration regarding the block caching mechanism and multithreaded programs running on SMP (multiprocessor) machines; see Multithreading overview for details.

 

 
Str::SetShutdownFlag
 
static void SetShutdownFlag (BOOL shutdown = TRUE)

When called with a TRUE parameter (the default), this method will internally call CompactFreeMemory and disable the caching mechanism. This is typically used towards the end of a program's execution, to avoid having memory leaks from cached blocks when exiting.

If the passed parameter is FALSE, Str will once again begin to build its block cache on subsequent Str operations.

 

See also: Constructors & utility, Manage buffer size