mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
Avoid unnecessary operation in PageAllocator.
There's no need to call `alignForward` before `VirtualAlloc`. From [MSDN](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc): ``` If the lpAddress parameter is NULL, this value is rounded up to the next page boundary ```
This commit is contained in:
parent
fe1b397606
commit
f71f27bcb0
@ -19,18 +19,22 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
|
|||||||
_ = log2_align;
|
_ = log2_align;
|
||||||
assert(n > 0);
|
assert(n > 0);
|
||||||
if (n > maxInt(usize) - (mem.page_size - 1)) return null;
|
if (n > maxInt(usize) - (mem.page_size - 1)) return null;
|
||||||
const aligned_len = mem.alignForward(usize, n, mem.page_size);
|
|
||||||
|
|
||||||
if (native_os == .windows) {
|
if (native_os == .windows) {
|
||||||
const addr = windows.VirtualAlloc(
|
const addr = windows.VirtualAlloc(
|
||||||
null,
|
null,
|
||||||
aligned_len,
|
|
||||||
|
// VirtualAlloc will round the length to a multiple of page size.
|
||||||
|
// VirtualAlloc docs: If the lpAddress parameter is NULL, this value is rounded up to the next page boundary
|
||||||
|
n,
|
||||||
|
|
||||||
windows.MEM_COMMIT | windows.MEM_RESERVE,
|
windows.MEM_COMMIT | windows.MEM_RESERVE,
|
||||||
windows.PAGE_READWRITE,
|
windows.PAGE_READWRITE,
|
||||||
) catch return null;
|
) catch return null;
|
||||||
return @ptrCast(addr);
|
return @ptrCast(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const aligned_len = mem.alignForward(usize, n, mem.page_size);
|
||||||
const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered);
|
const hint = @atomicLoad(@TypeOf(std.heap.next_mmap_addr_hint), &std.heap.next_mmap_addr_hint, .unordered);
|
||||||
const slice = posix.mmap(
|
const slice = posix.mmap(
|
||||||
hint,
|
hint,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user