enh(FileStream): Add FileStreamBuf::resizeBuffer to set larger internal buffers. (#4621)

Larger buffers improve performance significantly when streaming large quantity of data on very fast devices.
This commit is contained in:
Matej Kenda
2024-09-09 17:33:50 +02:00
committed by GitHub
parent 710c2a41f3
commit 91c256095f
8 changed files with 224 additions and 53 deletions

View File

@@ -36,7 +36,7 @@ public:
FileStreamBuf();
/// Creates a FileStreamBuf.
~FileStreamBuf();
~FileStreamBuf() override;
/// Destroys the FileStream.
void open(const std::string& path, std::ios::openmode mode);
@@ -49,10 +49,16 @@ public:
/// Closes the File stream buffer. Returns true if successful,
/// false otherwise.
std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out);
bool resizeBuffer(std::streamsize bufferSize) override;
/// Resizes internal buffer. Minimum size is BUFFER_SIZE.
/// Minimum is used when requested size is smaller.
/// Buffer can be resized only when the file is not open.
/// Returns true if resize succeeded.
std::streampos seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode = std::ios::in | std::ios::out) override;
/// Change position by offset, according to way and mode.
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out);
std::streampos seekpos(std::streampos pos, std::ios::openmode mode = std::ios::in | std::ios::out) override;
/// Change to specified position, according to mode.
void flushToDisk();
@@ -70,13 +76,13 @@ protected:
BUFFER_SIZE = 4096
};
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
int readFromDevice(char* buffer, std::streamsize length) override;
int writeToDevice(const char* buffer, std::streamsize length) override;
private:
std::string _path;
NativeHandle _fd;
std::streamoff _pos;
std::streamoff _pos {0};
};