Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function

allocBigPages

Private Function
std.heap.BrkAllocator.allocBigPages
fn allocBigPages(n: usize) usize

Params

  • n: usize

File

heap/BrkAllocator.zig:156
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
fn allocBigPages(n: usize) usize {
    const pow2_pages = math.ceilPowerOfTwoAssert(usize, n);
    const slot_size_bytes = pow2_pages * bigpage_size;
    const class = math.log2(pow2_pages);

    const top_free_ptr = global.big_frees[class];
    if (top_free_ptr != 0) {
        const node: *usize = @ptrFromInt(top_free_ptr + (slot_size_bytes - @sizeOf(usize)));
        global.big_frees[class] = node.*;
        return top_free_ptr;
    }

    if (builtin.cpu.arch.isWasm()) {
        comptime assert(std.heap.page_size_max == std.heap.page_size_min);
        const page_size = std.heap.page_size_max;
        const pages_per_bigpage = bigpage_size / page_size;
        const page_index = @wasmMemoryGrow(0, pow2_pages * pages_per_bigpage);
        if (page_index == -1) return 0;
        return @as(usize, @intCast(page_index)) * page_size;
    } else if (builtin.os.tag == .linux) {
        const prev_brk = global.prev_brk;
        const start_brk = if (prev_brk == 0)
            std.mem.alignForward(usize, std.os.linux.brk(0), bigpage_size)
        else
            prev_brk;
        const end_brk = start_brk + pow2_pages * bigpage_size;
        const new_prev_brk = std.os.linux.brk(end_brk);
        global.prev_brk = new_prev_brk;
        if (new_prev_brk != end_brk) return 0;
        return start_brk;
    } else {
        @compileError("no sbrk-like OS primitive available");
    }
}