Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cpp/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ struct alignas(32) persisted_matrix_gt {
if (fstat(file_descriptor, &stat_vectors) == -1)
throw std::invalid_argument("Couldn't obtain file stats");
raw_length = stat_vectors.st_size;
raw_handle = (std::uint8_t*)mmap(NULL, raw_length, PROT_READ, MAP_PRIVATE, file_descriptor, 0);
if (raw_handle == nullptr)
auto* result = mmap(NULL, raw_length, PROT_READ, MAP_PRIVATE, file_descriptor, 0);
if (result == MAP_FAILED)
throw std::invalid_argument("Couldn't memory-map the file");
raw_handle = (std::uint8_t*)result;
std::memcpy(&rows, raw_handle, sizeof(rows));
std::memcpy(&cols, raw_handle + sizeof(rows), sizeof(cols));
scalars = (scalar_t*)(raw_handle + sizeof(rows) + sizeof(cols));
Expand Down
3 changes: 2 additions & 1 deletion include/usearch/index_plugins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ class page_allocator_t {
#if defined(USEARCH_DEFINED_WINDOWS)
return (byte_t*)(::VirtualAlloc(NULL, count_bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
#else
return (byte_t*)mmap(NULL, count_bytes, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
auto* result = mmap(NULL, count_bytes, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
return (result == MAP_FAILED) ? nullptr : (byte_t*)result;
#endif
}

Expand Down