Skip to content

Commit c721cd0

Browse files
committed
Do not preload the file when the file size is too large (>1.9GB).
1 parent 69a729f commit c721cd0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

source/example.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ void read_ply_file(const std::string & filepath, const bool preload_into_memory
6363
{
6464
// For most files < 1gb, pre-loading the entire file upfront and wrapping it into a
6565
// stream is a net win for parsing speed, about 40% faster.
66-
if (preload_into_memory)
66+
std::ifstream file_helper(filepath, std::ios::binary);
67+
file_helper.seekg(0, std::ios::end);
68+
std::streamsize size_bytes = file_helper.tellg();
69+
file_helper.close();
70+
if (preload_into_memory && size_bytes <= 1.9e9)
6771
{
6872
byte_buffer = read_file_binary(filepath);
6973
file_stream.reset(new memory_stream((char*)byte_buffer.data(), byte_buffer.size()));

0 commit comments

Comments
 (0)