ezrosent / allocators-rs

Allocators in Rust
Apache License 2.0
311 stars 28 forks source link

mmap-alloc: Support resetting memory on Windows? #153

Open joshlf opened 6 years ago

joshlf commented 6 years ago

According to the Windows VirtualAlloc documentation, recent versions of Windows support "resetting" - calling VirtualAlloc with the MEM_RESET flag - which behaves essentially identically to madvise with MADV_DONTNEED on Linux and Mac:

Indicates that data in the memory range specified by lpAddress and dwSize is no longer of interest. The pages should not be read from or written to the paging file. However, the memory block will be used again later, so it should not be decommitted.

Similarly to madvise with MADV_WILLNEED, the MEM_RESET_UNDO flag is provided:

MEM_RESET_UNDO should only be called on an address range to which MEM_RESET was successfully applied earlier. It indicates that the data in the specified memory range specified by lpAddress and dwSize is of interest to the caller and attempts to reverse the effects of MEM_RESET. If the function succeeds, that means all data in the specified address range is intact. If the function fails, at least some of the data in the address range has been replaced with zeroes.

Questions:

Given a) the fact that adding this might require re-tooling the API and, b) the limited support, I'm inclined to leave this for now, but it may be worth coming back to in the future.