diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2022-01-26 21:12:36 +0100 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2022-01-26 21:12:36 +0100 |
| commit | bd98bcb93196c8fab6a2d6a797d85fc37c16b7ea (patch) | |
| tree | c5fb8b981146fd42016b0316f74f6abdb39e791a /src | |
| parent | 3f9ab56bd6ed874702900cc327894fc2593ab97b (diff) | |
Refactoring
Diffstat (limited to 'src')
| -rw-r--r-- | src/LargeFileStream.cpp | 6 | ||||
| -rw-r--r-- | src/LargeFileStream.hpp | 4 | ||||
| -rw-r--r-- | src/Types.hpp | 5 |
3 files changed, 8 insertions, 7 deletions
diff --git a/src/LargeFileStream.cpp b/src/LargeFileStream.cpp index 9c34274..3ae1ce2 100644 --- a/src/LargeFileStream.cpp +++ b/src/LargeFileStream.cpp @@ -19,7 +19,7 @@ void LargeFileStream::FromString(std::string content) { void LargeFileStream::ReadNextChunk() { chuck_count++; - file.read(buffer, BUFFER_SIZE); + file.read(buffer, FILE_BUFFER_SIZE); last_read_size = file.gcount(); } @@ -42,11 +42,11 @@ char LargeFileStream::operator[](loctype loc) { } // Goto the right memory chuck - loctype loc_chunk_count = loc / BUFFER_SIZE; + loctype loc_chunk_count = loc / FILE_BUFFER_SIZE; while (chuck_count < loc_chunk_count) { ReadNextChunk(); } - loctype offset = loc - (loc_chunk_count * BUFFER_SIZE); + loctype offset = loc - (loc_chunk_count * FILE_BUFFER_SIZE); // Ensure for EOF if (!file && offset >= last_read_size) { diff --git a/src/LargeFileStream.hpp b/src/LargeFileStream.hpp index 4900f35..fd072a1 100644 --- a/src/LargeFileStream.hpp +++ b/src/LargeFileStream.hpp @@ -5,8 +5,6 @@ #include <iostream> #include <string> -#define BUFFER_SIZE (1024 * 1024 / 2) - namespace pgnp { using namespace std; @@ -14,7 +12,7 @@ class LargeFileStream { /// @brief File to load ifstream file; /// @brief In memory buffer - char buffer[BUFFER_SIZE]; + char buffer[FILE_BUFFER_SIZE]; /// @brief Number of chuck read minus 1 loctype chuck_count; /// @brief Number of byte read during the last file access diff --git a/src/Types.hpp b/src/Types.hpp index 199b0df..a0c369d 100644 --- a/src/Types.hpp +++ b/src/Types.hpp @@ -1,7 +1,10 @@ #pragma once +// The corner stone of memory usage +#define FILE_BUFFER_SIZE (1024 * 1024 / 2) + namespace pgnp { typedef unsigned long long ull; typedef unsigned int uint; typedef ull loctype; // Choose location pointer type -}
\ No newline at end of file +} // namespace pgnp
\ No newline at end of file |
