NAME
TUI::Memory - memory-related utility functions
SYNOPSIS
use TUI::Memory qw(
lowMemory
newCache
disposeCache
);
my $cache;
newCache( $cache, 20 );
$cache->{$_} = $_
for 1 .. 150;
if ( lowMemory() ) {
$cache = {};
}
disposeCache( $cache );
DESCRIPTION
TUI::Memory provides the Turbo Vision compatible memory and cache management API used by the Perl port.
Caches are represented by ordinary hash references. Each allocation defines a guaranteed minimum size. However, the cache may also use additional capacity.
When lowMemory is called, the memory manager compares the combined number of cache entries with the configured heap limit. If the limit is exceeded, entries above each cache's guaranteed minimum size are discarded.
This module is purely functional and does not define any classes.
Commonly Used Features
Most applications interact with TUI::Memory only through the cache management API. Cache allocations are typically created with "newCache". A cache can be removed completely with "disposeCache".
The "lowMemory" function is typically used by the framework before creating or validating new views. If the combined guaranteed cache size still exceeds "$maxHeapSize" after reclaimable entries have been discarded, applications may reject additional allocations and report a low-memory condition.
Typical examples include large transient caches such as attribute conversion tables, glyph caches or other lookup structures whose size may grow with the complexity of the user interface.
VARIABLES
$maxHeapSize
Maximum combined number of entries permitted across all registered caches before the memory manager attempts to reclaim cache contents.
The name is retained from the original Turbo Vision API. In the Perl port the value represents cache entries rather than bytes of heap memory.
FUNCTIONS
disposeCache
disposeCache( $cache );
Calling disposeCache explicitly deregisters the cache, releases its metadata and sets the caller's cache variable to undef.
doneMemory
doneMemory();
Shuts down the memory subsystem.
getBufferSize
my $size = getBufferSize( $cache );
Returns the configured minimum size of a cache allocation.
Returns undef if the allocation is not known to the memory manager.
initMemory
initMemory();
Initializes the memory subsystem.
lowMemory
my $bool = lowMemory();
Calls the memory manager and returns true if the total cache usage, even after being reduced to the guaranteed minimum, is greater than $maxHeapSize.
Returns false if the total cache usage does not exceed $maxHeapSize.
memAlloc
my $cache = memAlloc( $size );
Creates a cache allocation with a guaranteed minimum size of $size.
newCache
newCache( $cache, $size );
Creates a cache allocation with a guaranteed minimum size of $size.
When the combined number of entries in all registered caches exceeds $maxHeapSize, entries above the guaranteed minimum size may be discarded automatically.
setBufferSize
my $bool = setBufferSize( $cache, $size );
Changes the guaranteed minimum size of a cache allocation.
Returns true if the size was accepted.
Returns false if the allocation is unknown or if the requested size would cause the combined guaranteed cache size to exceed $maxHeapSize.
SEE ALSO
AUTHORS
Borland International (original Turbo Vision design)
J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)
COPYRIGHT AND LICENSE
Copyright (c) 1990-1994, 1997 by Borland International
Copyright (c) 2021-2026 the "AUTHORS" as listed above.
This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).