DiskCacheSection: User Contributed Perl Documentation (3)Updated: 2000-04-29 |
DiskCacheSection: User Contributed Perl Documentation (3)Updated: 2000-04-29 |
use PDL::DiskCache; tie @a,'PDL::DiskCache', \@files, \%options; imag $a[3];
OO:
use PDL::DiskCache; $a = diskcache(\@files,\%options); imag $a->[3];
or
use PDL::DiskCache; $a = new PDL::DiskCache(\@files,\%options); imag $a->[4];
By default, PDL::DiskCache uses FITS files to represent the PDLs, but you can use any sort of file at all --- the read/write routines are the only place where it examines the underlying data, and you can specify the routines to use at construction time (or, of course, subclass PDL::DiskCache).
Items are swapped out on a FIFO basis, so if you have 10 slots and an expression with 10 items in it then you're OK (but you probably want more slots than that); but if you use more items in an expression than there are slots, thrashing will occur!
The hash ref interface is kept for historical reasons; you can access the sync() and purge() method calls directly from the returned array ref.
Since this is a tied array, things like Dumper traverse it transparently. That is sort-of good but also sort-of dangerous. You wouldn't want to PDL::Dumper::sdump() a large PDL::DiskCache, for example --- that would defeat the purpose of using a PDL::DiskCache in the first place.
This code may be distributed under the same terms as Perl itself (license available at http://www.perl.org). Copying, reverse engineering, distribution, and modification are explicitly allowed so long as this notice is preserved intact and modified versions are clearly marked as such.
If you modify the code and it's useful, please send a copy of the modified version to cdeforest@solar.stanford.edu.
This package comes with NO WARRANTY.
TIEARRAY(class,\@f,\%options)
rw (default 1): If set, allow reading and writing to the files. Because there's currently no way to determine reliably whether a PDL has been modified, rw files are always written to disk when they're swapped out --- this causes a slight performance hit.
mem (default 20): Number of files to be cached in memory at once.
read (default \&rfits): A function ref pointing to code that will read list objects from disk. The function must have the same syntax as rfits: $object = rfits(filename).
write (default \&wfits): A function ref pointing to code that will write list objects to disk. The function must have the same syntax as wfits: func(object,filename).
bless (default 0): If set to a nonzero value, then the array ref gets blessed into the DiskCache class for for easier access to the ``purge'' and ``sync'' methods. This means that you can say "$a-"sync> instead of the more complex "(%{tied @$a})-"sync>, but "ref $a" will return ``PDL::DiskCache'' instead of ``ARRAY'', which could break some code.
verbose (default 0): Get chatty.
For most uses, a nice MODIFIED flag in the data structure could save some hassle here. But PDLs can get modified out from under us with slicing and .= --- so for now we always assume everything is tainted and must be written to disk.