csMemoryMappedIO Class Reference
Defines a simple memory-mapped IO class that is portable. More...
#include <csutil/mmapio.h>
Public Member Functions | |
csMemoryMappedIO (unsigned _block_size, char const *filename, iVFS *vfs=0) | |
Block size is the size of blocks that you want to get from the file, filename is the name of the file to map. | |
~csMemoryMappedIO () | |
Destroys the mmapio object, closes open files, and releases memory. | |
void * | GetPointer (unsigned int index) |
This pointer will only be valid for a little while. | |
bool | IsValid () |
Returns true the memory was mapped successfully. |
Detailed Description
Defines a simple memory-mapped IO class that is portable.Requires that data is organized in fixed block sizes.
Design notes:
1. Although the offset and page in the cache block can both be calculated from either value, I chose to precalculate and store BOTH items. The reason for this is that it avoids one multiplication on each access, and one division when paging data in to cache. For the default values data storage per cache is 8192 bytes with 20 bytes additional overhead. This means that 0.2% of the data is overhead. That's worth it to avoid a heavy op like multiplication
2. Usage of the singly-linked list for storage was chosen over a static array of cache blocks because there's no simple way to provide a direct index into the cache list from the index or page. Since we can probably guarantee that all blocks are NOT going to be in memory at once, we cannot index into the array based on a page index, etc. A sorted list would probably provide the fastest lookup times, but would it be worth the overhead? A hash table provides a number of short lists, which in this case are unsorted. Using QuickSort, lookup on a sorted table of 2048 entries would take about log2(2048) operations. With the default hash table size, each list is about 1.5 entries long if spread uniformly. This means that most lookups on a cache of this size should take between two and four operations per (counting the modulus.) While the hash table does consume about 4k more memory, I think the slight memory usage is worth it, considering the massive speedup.
Definition at line 78 of file mmapio.h.
Constructor & Destructor Documentation
|
Block size is the size of blocks that you want to get from the file, filename is the name of the file to map.
Indexes will be resolved to absolute_index=index*block_size. If you supply a VFS, |
|
Destroys the mmapio object, closes open files, and releases memory.
|
Member Function Documentation
|
This pointer will only be valid for a little while. Read, at least until the next call to GetPointer. NEVER EVER EVER SAVE THIS POINTER. You must recall this pointer when you want access to the data again. |
|
Returns true the memory was mapped successfully.
|
The documentation for this class was generated from the following file:
- csutil/mmapio.h
Generated for Crystal Space by doxygen 1.3.9.1