Maintains memory blocks within a file.
More...
#include <FileAllocator.h>
|
static FileOffset | minimum_size |
| To avoid allocating tiny areas, also to avoid splitting free blocks into pieces that are then too small to be ever useful, all memory regions are at least this big. More...
|
|
static FileOffset | file_size_increment |
| Setting file_size_increment will cause the file size to jump in the given increments. More...
|
|
Maintains memory blocks within a file.
The FileAllocator maintains the space in a given file by keeping track of allocated blocks. Sections can also be released, in which case they are placed in a free-list for future allocations.
FileAllocator::FileAllocator |
( |
| ) |
|
Constructor/destructor check if attach/detach have been called.
We could have made these perform the attach/detach, but then the error reporting would have had to use exceptions which we'd like to avoid.
Allocate a block with given size, returning a file offset (for fseek).
- See Also
- free()
- Exceptions
-
bool FileAllocator::attach |
( |
FILE * |
f, |
|
|
FileOffset |
reserved_space, |
|
|
bool |
init |
|
) |
| |
Must be invoked to attach (& initialize) a file.
Can be invoked on an empty file with init=true, in thich case the reserved space and some FileAllocator header will be added to the file. Can also be invoked on an existing file (init=false or true) which was initialized by the FileAllocator, in which case the reserved_space has to match the value that was used when initializing the file!
init=true means this file is used for writing, and we are allowed to create a new file allocator header for an empty file.
- Returns
- true when an empty file was initialized. Otherwise, some weak tests are performed so see if this file does indeed contain a FileAllocator header, and false is returned.
- Exceptions
-
bool FileAllocator::dump |
( |
int |
level = 1 , |
|
|
FILE * |
out = stdout |
|
) |
| |
Show ASCII-type info about the file structure.
This routines lists all the allocated and free blocks together with some other size information. It also performs some sanity checks. When called with level=0, it will only perform the tests and only report possible problems.
Should not throw exceptions but simply return false on errors.
- Parameters
-
level | Level of verbosity. |
out | When non-zero, it is used instead of stdout. |
Returns true for 'OK'.
Release a file block (will be placed in free list).
- Parameters
-
offset | A file offset previously obtained from allocate() |
- Warning
- It is an error to free space that wasn't allocated. There is no 100% dependable way to check this, but free() will perform some basic test and return false for inknown memory regions.
- Exceptions
-
FILE* FileAllocator::getFile |
( |
| ) |
const |
- Returns
- After attaching to a file, this returns the file.
- Returns
- Total size of file in bytes.
Setting file_size_increment will cause the file size to jump in the given increments.
To avoid allocating tiny areas, also to avoid splitting free blocks into pieces that are then too small to be ever useful, all memory regions are at least this big.
Meaning: Whenever you allocate less than minimum_size, you will get a block that's actually minimum_size.
The documentation for this class was generated from the following file:
- /home/malitsky/projects/epics-archiver/sourceforge/trunk/ea4-cpp/include/common/storage/FileAllocator.h