cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
OS Virtual Memory

Low-level OS page reservation, commitment, decommitment, and release. More...

Functions

void * os_mem_reserve (usize size)
 Reserves a block of virtual address space.
b32 os_mem_commit (void *ptr, usize size)
 Commits physical RAM to a previously reserved address range.
void os_mem_decommit (void *ptr, usize size)
 Decommits physical RAM, returning it to the OS while keeping the address space.
void os_mem_release (void *ptr, usize size)
 Releases a reserved virtual address range entirely back to the OS.

Detailed Description

Low-level OS page reservation, commitment, decommitment, and release.

Function Documentation

◆ os_mem_commit()

b32 os_mem_commit ( void * ptr,
usize size )

Commits physical RAM to a previously reserved address range.

Note
The committed memory is zero-initialized by the OS on first access.
Parameters
ptrPointer within a previously reserved block.
sizeNumber of bytes to commit (rounded up to the OS page size internally).
Returns
1 (true) on success, 0 (false) if the OS refused (e.g., out of physical RAM).

Definition at line 29 of file mem_os.c.

Here is the caller graph for this function:

◆ os_mem_decommit()

void os_mem_decommit ( void * ptr,
usize size )

Decommits physical RAM, returning it to the OS while keeping the address space.

Note
The virtual address range remains reserved and valid for a future os_mem_commit(). Any attempt to read or write decommitted memory before recommitting it is undefined behavior (access violation / segfault).
Parameters
ptrPointer to the start of the committed range.
sizeNumber of bytes to decommit.

Definition at line 39 of file mem_os.c.

◆ os_mem_release()

void os_mem_release ( void * ptr,
usize size )

Releases a reserved virtual address range entirely back to the OS.

Warning
After this call, ptr is invalid. Any access is undefined behavior.
Note
On Windows, size is ignored (the OS tracks the full reservation size). On POSIX, size must match the value passed to os_mem_reserve().
Parameters
ptrPointer returned by os_mem_reserve().
sizeTotal size that was originally passed to os_mem_reserve().

Definition at line 50 of file mem_os.c.

Here is the caller graph for this function:

◆ os_mem_reserve()

void * os_mem_reserve ( usize size)

Reserves a block of virtual address space.

Note
Uses ZERO physical RAM. The returned pointer cannot be read or written until the range (or a sub-range) is committed with os_mem_commit().
Parameters
sizeThe number of bytes to reserve. Can safely be in the gigabyte range.
Returns
Pointer to the start of the reserved range, or NULL on failure.

Definition at line 18 of file mem_os.c.

Here is the caller graph for this function: