Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
7abb9e2
fix some
JalinWang Feb 9, 2026
c74f276
fix platform related
JalinWang Feb 10, 2026
7fb10c4
hnsw VLAs
JalinWang Feb 10, 2026
72f7214
hnsw sparse VLAs
JalinWang Feb 10, 2026
89f02f5
flexible array member
JalinWang Feb 10, 2026
8dc698b
type define
JalinWang Feb 10, 2026
5521744
vla
JalinWang Feb 10, 2026
88de5da
vla + uint8_t
JalinWang Feb 10, 2026
8b3b3ef
__VA_ARGS__
JalinWang Feb 10, 2026
e8dc871
iota
JalinWang Feb 10, 2026
673cf8e
ssize
JalinWang Feb 10, 2026
431b541
sum4
JalinWang Feb 10, 2026
66a8c56
fixup! hnsw VLAs
JalinWang Mar 10, 2026
28d8c68
win header, file/time/sleep implement
JalinWang Mar 11, 2026
3255327
func overload
JalinWang Mar 11, 2026
228dfae
vla
JalinWang Mar 11, 2026
402f2a1
TODO: should just support std::uniform_int_distribution<int8_t> inste…
JalinWang Mar 11, 2026
fb8511f
uint -> unsigned int
JalinWang Mar 11, 2026
828e457
TODO: unknown reason
JalinWang Mar 11, 2026
83a6423
TODO: skip tests
JalinWang Mar 11, 2026
c26de94
TODO: may revert
JalinWang Mar 11, 2026
60da06e
TODO: rocksdb can't find lz4, could be optimized
JalinWang Mar 11, 2026
3a267a0
third party Cmakelist: naming, compiling options
JalinWang Mar 11, 2026
c575663
TODO: designated init & c++ 20, may revert
JalinWang Mar 11, 2026
539dc20
fix compiler options
JalinWang Mar 11, 2026
c92a51c
TODO: ignore some warning
JalinWang Mar 11, 2026
de9724b
TODO: to verify sparsehash's patch
JalinWang Mar 11, 2026
3dab143
msvc debug will validate the boundary
JalinWang Mar 13, 2026
52170b9
fix -1UL: On MSVC, unsigned long is 32-bit, so -1UL is 0xFFFFFFFF no…
JalinWang Mar 13, 2026
47df026
fix flexible structure
JalinWang Mar 13, 2026
1f87aa7
TODO: verify the fix of mmap alignment
JalinWang Mar 13, 2026
d9abe33
fix ctest failure by storage.close
JalinWang Mar 13, 2026
689bb04
fix mutex by atomic: TestDumpIndexAndAdd test uses mutex.unlock() fro…
JalinWang Mar 13, 2026
9b7321f
storage close
JalinWang Mar 13, 2026
d4d4a0b
TODO: unify the file cleanup of UTs
JalinWang Mar 13, 2026
9133a76
TODO: currently replace dll by static to support indexFactory registe…
JalinWang Mar 13, 2026
938e5a5
ignore more
JalinWang Mar 13, 2026
6fb2707
fix antlr4 release
JalinWang Mar 13, 2026
0e427a2
fix: gtest link warning
JalinWang Mar 13, 2026
1948e39
revert c++20
JalinWang Mar 13, 2026
7a5cfb6
platform related code refactor
JalinWang Mar 16, 2026
ed57793
buffer manager cleanup to avoid ctest failure
JalinWang Mar 16, 2026
5c61212
refactor: file remove/test setup
JalinWang Mar 16, 2026
c6e5012
fix
JalinWang Mar 16, 2026
a7e5190
fix memory limit
JalinWang Mar 16, 2026
e7bbbfe
fix segment_helper_test
JalinWang Mar 16, 2026
e9e9c5d
Merge branch 'main' into feat/win-compilation
JalinWang Mar 16, 2026
5c89b6e
fix write_recovery_test
JalinWang Mar 16, 2026
62683bf
fix __m64
JalinWang Mar 16, 2026
cda7187
fix linux ut
JalinWang Mar 16, 2026
26085af
fix write_recovery_test on linux
JalinWang Mar 17, 2026
6795a6c
format
JalinWang Mar 17, 2026
a715ccc
fix `pip install`
JalinWang Mar 18, 2026
7d50164
fix: only MSVC use C99 flexible array member
JalinWang Mar 18, 2026
05cb8e6
fix RemoveDirectory on windows
JalinWang Mar 18, 2026
194c2d6
proper cleanup
JalinWang Mar 19, 2026
488b9a5
windows file api fix
JalinWang Mar 19, 2026
2af50d5
fixup! proper cleanup
JalinWang Mar 19, 2026
59d7622
misc: reformat code
JalinWang Mar 19, 2026
4d68a28
Merge branch 'main' into feat/win-compilation-merge
JalinWang Mar 19, 2026
2d6a50b
Merge branch 'main' into feat/win-compilation-merge-new
JalinWang Mar 20, 2026
f01b37e
fix: post-merge#83 CE on windows
JalinWang Mar 19, 2026
6441c43
fix: MSVC does not define the preprocessor macro __F16C__
JalinWang Mar 20, 2026
afe4013
fix: RemoveDirectory should return false for non-dir paths
JalinWang Mar 20, 2026
2ab5b3f
fix: MSVC doesn't define __AVX512VNNI__ & fix always_inline
JalinWang Mar 20, 2026
3253bed
fix: pypi wheel DLL
JalinWang Mar 20, 2026
15f41d5
fix: make COLLECTION_PATH_REGEX compatible with Windows
JalinWang Mar 20, 2026
f76effe
chore: rm comments
JalinWang Mar 20, 2026
d340290
chore: reformat
JalinWang Mar 20, 2026
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
43 changes: 41 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,36 @@ cmake_policy(SET CMP0077 NEW)
project(zvec)
set(CC_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror=return-type")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=return-type")
if(MSVC)
set(INTTYPES_FORMAT VC7)
add_compile_options(/FS) #handle .pdb
add_compile_options(/EHsc) # def c++ exception behavior
add_compile_options(/Zc:preprocessor)
add_compile_options(/we4716) # -Werror=return-type


###### reduce output length to make vibe coding work better :), which should be removed or solved later
add_compile_options(/wd4267 /wd4244)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分warning的编号可以统一放在一个add_compile_options里头吧,并且加上每个编号的注释。

add_compile_options(/wd4146) # unary minus operator applied to unsigned type #usage: uint32_t seg_id_{-1U};
add_compile_options(/wd4310) # warning C4310: cast truncates constant value
Comment on lines +16 to +17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broad narrowing-conversion warnings suppressed without fix

/wd4267 (conversion from size_t to a smaller type) and /wd4244 (general type narrowing) are silently disabled with a comment acknowledging they need to be resolved. These two warnings regularly surface real runtime bugs (e.g., size_tint truncation on 64-bit data, unintended float→int narrowing). Leaving them suppressed while the PR is merged makes it easy for future changes to introduce silent truncation bugs that are never caught.

Consider replacing the blanket suppression with targeted #pragma warning(suppress: ...) at the specific call sites that are genuinely safe, rather than disabling them project-wide.

add_compile_options(/wd4530) # warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
add_compile_options(/wd4251) #protobuf
add_compile_options(/wd4245 /wd4334 /wd4702 /wd4305 /wd4099)
add_compile_options(/wd4200) # flexible structure

# //warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
# keeps |= (1 << k);
add_compile_options(/wd4334)
######

#TODO(windows): to be verified
add_definitions(-DARROW_STATIC -DPARQUET_STATIC -DARROW_ACERO_STATIC -DARROW_DS_STATIC -DARROW_COMPUTE_STATIC)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个有点过于hack了吧。。不加难道会有问题吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the TODO comment suggests, this needs re-verification and refinement. I'll address it after the Windows CI is set up.



else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror=return-type")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=return-type")
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed")
Expand All @@ -27,6 +55,7 @@ endif()

include_directories(${PROJECT_ROOT_DIR}/src/include)
include_directories(${PROJECT_ROOT_DIR}/src)
include_directories(${PROJECT_ROOT_DIR})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要加上这个?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To include tests/test_util.h, which contains definitions for sleep and a wildcard-supporting remove function. I'll clean this up later by moving sleep to platform.h and removing wildcard usage from the UTs.


option(BUILD_PYTHON_BINDINGS "Build Python bindings using pybind11" OFF)
message(STATUS "BUILD_PYTHON_BINDINGS:${BUILD_PYTHON_BINDINGS}")
Expand Down Expand Up @@ -99,4 +128,14 @@ if(BUILD_PYTHON_BINDINGS)

message(STATUS "Zvec install path: ${ZVEC_PY_INSTALL_DIR}")
install(TARGETS _zvec LIBRARY DESTINATION ${ZVEC_PY_INSTALL_DIR})

if(MSVC)
install(FILES
$<TARGET_FILE:glog>
$<TARGET_FILE:gflags>
$<TARGET_FILE:roaring>
$<TARGET_FILE:libprotobuf>
DESTINATION ${ZVEC_PY_INSTALL_DIR}
)
endif()
endif()
34 changes: 33 additions & 1 deletion cmake/bazel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ function(_target_link_libraries _NAME)
get_target_property(ALWAYS_LINK ${LIB} ALWAYS_LINK)
if(ALWAYS_LINK)
list(APPEND LOCAL_RESULT ${LIB})
elseif(MSVC AND TARGET ${LIB}_static)
get_target_property(_SIBLING_AL ${LIB}_static ALWAYS_LINK)
if(_SIBLING_AL)
list(APPEND LOCAL_RESULT ${LIB}_static)
endif()
endif()

get_target_property(DEP_LIBS ${LIB} INTERFACE_LINK_LIBRARIES)
Expand Down Expand Up @@ -652,6 +657,30 @@ function(_target_link_libraries _NAME)

list(REMOVE_DUPLICATES ALL_LIBS_TO_PROCESS)

# On MSVC, each DLL has its own copy of template statics (e.g. Factory
# singletons), so registrations inside a DLL are invisible to the exe.
# Substitute SHARED libs with their ALWAYS_LINK _static counterparts and
# use /WHOLEARCHIVE so all registration code lives in the same module.
if(MSVC)
set(_SUBSTITUTED_LIBS "")
foreach(LIB ${ALL_LIBS_TO_PROCESS})
if(TARGET ${LIB} AND TARGET ${LIB}_static)
get_target_property(_LIB_TYPE ${LIB} TYPE)
get_target_property(_STATIC_AL ${LIB}_static ALWAYS_LINK)
if("${_LIB_TYPE}" STREQUAL "SHARED_LIBRARY" AND _STATIC_AL)
list(APPEND _SUBSTITUTED_LIBS ${LIB}_static)
list(APPEND ALL_ALWAYS_LINK_LIBS ${LIB}_static)
continue()
endif()
endif()
list(APPEND _SUBSTITUTED_LIBS ${LIB})
endforeach()
set(ALL_LIBS_TO_PROCESS ${_SUBSTITUTED_LIBS})
if(ALL_ALWAYS_LINK_LIBS)
list(REMOVE_DUPLICATES ALL_ALWAYS_LINK_LIBS)
endif()
endif()

foreach(LIB ${ALL_LIBS_TO_PROCESS})
if(NOT TARGET ${LIB})
list(APPEND LINK_LIBS ${LIB})
Expand All @@ -672,7 +701,7 @@ function(_target_link_libraries _NAME)
endif()
else()
# Microsoft Visual C++
list(APPEND LINK_LIBS /WHOLEARCHIVE:$<TARGET_FILE:${LIB}>)
list(APPEND MSVC_WHOLEARCHIVE_OPTS /WHOLEARCHIVE:$<TARGET_FILE:${LIB}>)
get_target_property(OTHER_LINK_LIBS ${LIB} INTERFACE_LINK_LIBRARIES)
if(OTHER_LINK_LIBS)
foreach(OTHER_LIB ${OTHER_LINK_LIBS})
Expand All @@ -691,6 +720,9 @@ function(_target_link_libraries _NAME)
endforeach()

target_link_libraries(${_NAME} ${LINK_LIBS})
if(MSVC_WHOLEARCHIVE_OPTS)
target_link_options(${_NAME} PRIVATE ${MSVC_WHOLEARCHIVE_OPTS})
endif()
if(LIBS_DEPS)
add_dependencies(${_NAME} ${LIBS_DEPS})
target_include_directories(${_NAME} PRIVATE "${LIBS_INCS}")
Expand Down
2 changes: 1 addition & 1 deletion cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function(apply_patch_once patch_name target_dir patch_file)

#message(STATUS "Applying patch '${patch_name}' to ${target_dir} ...")
execute_process(
COMMAND patch -p1 -i "${patch_file}"
COMMAND git apply --ignore-space-change --ignore-whitespace "${patch_file}"
WORKING_DIRECTORY "${target_dir}"
RESULT_VARIABLE patch_result
OUTPUT_VARIABLE patch_stdout
Expand Down
17 changes: 11 additions & 6 deletions src/ailego/buffer/buffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct BufferManager::BufferContext {

~BufferContext() {
if (vector) {
free(vector);
ailego_aligned_free(vector);
}
}

Expand Down Expand Up @@ -256,15 +256,15 @@ bool BufferManager::BufferContext::read_vector() {
}
AILEGO_DEFER([this] { file.close(); });
uint32_t len = id.vector().length;
auto ret = posix_memalign((void **)&vector, 64, len); // 64-byte alignment
if (ret != 0 || vector == nullptr) {
vector = (uint8_t *)ailego_aligned_malloc(len, 64); // 64-byte alignment
if (vector == nullptr) {
LOG_ERROR("Failed to allocate buffer for file[%s]", file_name.c_str());
return false;
}
uint32_t offset = id.vector().offset;
if (file.read(offset, vector, len) != len) {
LOG_ERROR("Failed to read file[%s]", file_name.c_str());
free(vector);
ailego_aligned_free(vector);
vector = nullptr;
return false;
}
Expand Down Expand Up @@ -390,7 +390,7 @@ class BufferManager::BufferPool {
if (victim->id.type == BufferID::TYPE::PARQUET) {
victim->arrow_refs.clear();
} else {
free(victim->vector);
ailego_aligned_free(victim->vector);
victim->vector = nullptr;
}
victim->state = BufferContext::State::IDLE;
Expand Down Expand Up @@ -585,10 +585,15 @@ uint64_t BufferManager::total_size_in_bytes() const {
}


BufferManager::~BufferManager() {
void BufferManager::cleanup() {
for (auto pool : pools_) {
delete pool;
}
pools_.clear();
}

BufferManager::~BufferManager() {
cleanup();
}


Expand Down
37 changes: 37 additions & 0 deletions src/ailego/buffer/buffer_pool.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#include <zvec/ailego/buffer/buffer_pool.h>
#include <zvec/core/framework/index_logger.h>

#if defined(_MSC_VER)
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
static ssize_t zvec_pread(int fd, void *buf, size_t count, size_t offset) {
HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
if (handle == INVALID_HANDLE_VALUE) return -1;
OVERLAPPED ov = {};
ov.Offset = static_cast<DWORD>(offset & 0xFFFFFFFF);
ov.OffsetHigh = static_cast<DWORD>(offset >> 32);
DWORD bytes_read = 0;
if (!ReadFile(handle, buf, static_cast<DWORD>(count), &bytes_read, &ov)) {
return -1;
}
return static_cast<ssize_t>(bytes_read);
}
#endif

namespace zvec {
namespace ailego {

Expand Down Expand Up @@ -167,13 +186,23 @@ void LPMap::recycle(moodycamel::ConcurrentQueue<char *> &free_buffers) {
}

VecBufferPool::VecBufferPool(const std::string &filename) {
#if defined(_MSC_VER)
fd_ = _open(filename.c_str(), O_RDONLY | _O_BINARY);
#else
fd_ = open(filename.c_str(), O_RDONLY);
#endif
if (fd_ < 0) {
throw std::runtime_error("Failed to open file: " + filename);
}
#if defined(_MSC_VER)
struct _stat64 st;
if (_fstat64(fd_, &st) < 0) {
_close(fd_);
#else
struct stat st;
if (fstat(fd_, &st) < 0) {
::close(fd_);
#endif
throw std::runtime_error("Failed to stat file: " + filename);
}
file_size_ = st.st_size;
Expand Down Expand Up @@ -247,7 +276,11 @@ char *VecBufferPool::acquire_buffer(block_id_t block_id, size_t offset,
}
}

#if defined(_MSC_VER)
ssize_t read_bytes = zvec_pread(fd_, buffer, size, offset);
#else
ssize_t read_bytes = pread(fd_, buffer, size, offset);
#endif
if (read_bytes != static_cast<ssize_t>(size)) {
LOG_ERROR("Buffer pool failed to read file at offset: %zu", offset);
free_buffers_.enqueue(buffer);
Expand All @@ -257,7 +290,11 @@ char *VecBufferPool::acquire_buffer(block_id_t block_id, size_t offset,
}

int VecBufferPool::get_meta(size_t offset, size_t length, char *buffer) {
#if defined(_MSC_VER)
ssize_t read_bytes = zvec_pread(fd_, buffer, length, offset);
#else
ssize_t read_bytes = pread(fd_, buffer, length, offset);
#endif
if (read_bytes != static_cast<ssize_t>(length)) {
LOG_ERROR("Buffer pool failed to read file at offset: %zu", offset);
return -1;
Expand Down
4 changes: 3 additions & 1 deletion src/ailego/internal/cpu_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "cpu_features.h"
#include <cstddef>

#if !defined(_MSC_VER) && !defined(__ARM_ARCH)
#if defined(_MSC_VER)
#include <intrin.h>
#elif !defined(__ARM_ARCH)
#include <cpuid.h>
#endif

Expand Down
68 changes: 52 additions & 16 deletions src/ailego/io/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,9 @@ bool File::create(const char *path, size_t len, bool direct) {

// Try opening or creating the file
HANDLE file_handle =
CreateFileA(path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
CreateFileA(path, GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
ailego_false_if_false(file_handle != INVALID_HANDLE_VALUE);

// Truncate the file to the specified size
Expand All @@ -432,7 +433,8 @@ bool File::create(const char *path, size_t len, bool direct) {
// Close and reopen file
CloseHandle(file_handle);
file_handle = CreateFileA(
path, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr,
path, GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, nullptr);
ailego_false_if_false(file_handle != INVALID_HANDLE_VALUE);
}
Expand All @@ -453,7 +455,8 @@ bool File::open(const char *path, bool rdonly, bool direct) {
}
HANDLE file_handle =
CreateFileA(path, (rdonly ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE),
FILE_SHARE_READ, nullptr, OPEN_EXISTING, flags, nullptr);
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING, flags, nullptr);
ailego_false_if_false(file_handle != INVALID_HANDLE_VALUE);

read_only_ = rdonly;
Expand Down Expand Up @@ -639,14 +642,28 @@ ssize_t File::offset(void) const {
}

void *File::MemoryMap(NativeHandle handle, ssize_t off, size_t len, int opts) {
LARGE_INTEGER file_size;
file_size.QuadPart = len;
// Root cause: Windows MapViewOfFile requires the file offset to be aligned to
// the allocation granularity (64 KB), but segment offsets were only
// page-aligned (4 KB). Also, CreateFileMapping was using len instead of
// off + len as the max size.
//
// Fix: Align the view offset down to allocation granularity, adjust the map
// length, and return base + excess. MemoryUnmap recovers the base by rounding
// down to granularity.

SYSTEM_INFO si;
GetSystemInfo(&si);
DWORD granularity = si.dwAllocationGranularity;
ssize_t aligned_off = (off / (ssize_t)granularity) * (ssize_t)granularity;
size_t excess = (size_t)(off - aligned_off);

LARGE_INTEGER max_size;
max_size.QuadPart = off + len;

// Create map object
HANDLE file_mapping = CreateFileMapping(
handle, nullptr,
((opts & File::MMAP_READONLY) ? PAGE_READONLY : PAGE_READWRITE),
file_size.HighPart, file_size.LowPart, nullptr);
max_size.HighPart, max_size.LowPart, nullptr);
ailego_null_if_false(file_mapping != nullptr);

DWORD desired_access = FILE_MAP_READ;
Expand All @@ -656,14 +673,17 @@ void *File::MemoryMap(NativeHandle handle, ssize_t off, size_t len, int opts) {
if (!(opts & File::MMAP_SHARED)) {
desired_access |= FILE_MAP_COPY;
}
file_size.QuadPart = off;

// Map the whole file to memory and close handle
void *addr = MapViewOfFile(file_mapping, desired_access, file_size.HighPart,
file_size.LowPart, 0);
LARGE_INTEGER view_offset;
view_offset.QuadPart = aligned_off;
size_t view_len = len + excess;

void *base = MapViewOfFile(file_mapping, desired_access, view_offset.HighPart,
view_offset.LowPart, view_len);
CloseHandle(file_mapping);

ailego_null_if_false(addr);
ailego_null_if_false(base);
void *addr = (char *)base + excess;
if (opts & File::MMAP_LOCKED) {
VirtualLock(addr, len);
}
Expand All @@ -673,8 +693,17 @@ void *File::MemoryMap(NativeHandle handle, ssize_t off, size_t len, int opts) {
return addr;
}

void *File::MemoryMap(size_t, int) {
return nullptr;
void *File::MemoryMap(size_t len, int opts) {
void *addr =
VirtualAlloc(nullptr, len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
ailego_null_if_false(addr);
if (opts & File::MMAP_LOCKED) {
VirtualLock(addr, len);
}
if (opts & File::MMAP_WARMUP) {
File::MemoryWarmup(addr, len);
}
return addr;
}

void *File::MemoryRemap(void *, size_t, void *, size_t) {
Expand All @@ -683,7 +712,14 @@ void *File::MemoryRemap(void *, size_t, void *, size_t) {

void File::MemoryUnmap(void *addr, size_t /*len*/) {
ailego_return_if_false(addr);
UnmapViewOfFile(addr);
MEMORY_BASIC_INFORMATION mbi;
if (VirtualQuery(addr, &mbi, sizeof(mbi))) {
if (mbi.Type == MEM_MAPPED) {
UnmapViewOfFile(mbi.AllocationBase);
} else {
VirtualFree(mbi.AllocationBase, 0, MEM_RELEASE);
}
}
}

bool File::MemoryFlush(void *addr, size_t /*len*/) {
Expand Down
Loading
Loading