DoxigAlpha

rawCAlloc

Function parameters

Parameters

#
context:*anyopaque
len:usize
return_address:usize

Type definitions in this namespace

Types

#
GeneralPurposeAllocatorConfig
Deprecated; to be removed after 0.14.0 is tagged.

Functions in this namespace

Functions

#
GeneralPurposeAllocator
Deprecated; to be removed after 0.14.0 is tagged.
pageSize
If the page size is comptime-known, return value is comptime.
defaultQueryPageSize
The default implementation of `std.options.queryPageSize`.
stackFallback
Returns a `StackFallbackAllocator` allocating using either a
StackFallbackAllocator
An allocator that attempts to allocate using a
testAllocator
This one should not try alignments that exceed what C malloc can handle.

TODO Utilize this on Windows.

Values

#
next_mmap_addr_hint
TODO Utilize this on Windows.
page_size_min
comptime-known minimum page size of the target.
page_size_max
comptime-known maximum page size of the target.
c_allocator
Supports the full Allocator interface, including alignment, and exploiting
raw_c_allocator
Asserts allocations are within `@alignOf(std.c.max_align_t)` and directly
page_allocator
On operating systems that support memory mapping, this allocator makes a
smp_allocator
= .{ .ptr = undefined, .vtable = &SmpAllocator.vtable, }
wasm_allocator
This allocator is fast, small, and specific to WebAssembly.

Source

Implementation

#
fn rawCAlloc(
    context: *anyopaque,
    len: usize,
    alignment: Alignment,
    return_address: usize,
) ?[*]u8 {
    _ = context;
    _ = return_address;
    assert(alignment.compare(.lte, .of(std.c.max_align_t)));
    // Note that this pointer cannot be aligncasted to max_align_t because if
    // len is < max_align_t then the alignment can be smaller. For example, if
    // max_align_t is 16, but the user requests 8 bytes, there is no built-in
    // type in C that is size 8 and has 16 byte alignment, so the alignment may
    // be 8 bytes rather than 16. Similarly if only 1 byte is requested, malloc
    // is allowed to return a 1-byte aligned pointer.
    return @ptrCast(c.malloc(len));
}