Tools.h++ Manual
21-50 104011 Tandem Computers Incorporated
21
RRWCacheManager
Synopsis
#include <rw/cacheman.h>
RWFile f("file.dat"); // Construct a file
RWCacheManager(&f, 100); // Cache 100 byte blocks to
file.dat
Description Class
RWCacheManager
caches fixed length blocks to and from an associated
RWFile
. The block size can be of any length and is set at construction time.
The number of cached blocks can also be set at construction time.
Writes to the file may be deferred. Use member function
flush()
to have any
pending writes performed.
Example
#include <rw/cacheman.h>
#include <rw/rwfile.h>
struct Record {
int i;
float f;
char str[15];
};
main()
{
RWoffset loc;
RWFile file("file.dat"); // Construct a file
// Construct a cache, using 20 slots for struct Record:
RWCacheManager cache(&file, sizeof(Record), 20);
Record r;
// ...
cache.write(loc, &r);
// ...
cache.read(loc, &r);
}