diff options
| author | Pieter Wuille <[email protected]> | 2012-08-16 02:21:28 +0200 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2012-10-20 23:08:57 +0200 |
| commit | bba89aa82a80f0373dcb7288d96d5b0fcb453d73 (patch) | |
| tree | f3b4fd8649021b52e19cfdf4620ffead5f30910e /src/util.cpp | |
| parent | Multiple blocks per file (diff) | |
| download | discoin-bba89aa82a80f0373dcb7288d96d5b0fcb453d73.tar.xz discoin-bba89aa82a80f0373dcb7288d96d5b0fcb453d73.zip | |
Pre-allocate block and undo files in chunks
Introduce a AllocateFileRange() function in util, which wipes or
at least allocates a given range of a file. It can be overriden
by more efficient OS-dependent versions if necessary.
Block and undo files are now allocated in chunks of 16 and 1 MiB,
respectively.
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index c72b84bfa..916288645 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1137,6 +1137,20 @@ int GetFilesize(FILE* file) return nFilesize; } +// this function tries to make a particular range of a file allocated (corresponding to disk space) +// it is advisory, and the range specified in the arguments will never contain live data +void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { + static const char buf[65536] = {}; + fseek(file, offset, SEEK_SET); + while (length > 0) { + unsigned int now = 65536; + if (length < now) + now = length; + fwrite(buf, 1, now, file); // allowed to fail; this function is advisory anyway + length -= now; + } +} + void ShrinkDebugFile() { // Scroll debug.log if it's getting too big |