cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
mem_os.h File Reference

Operating System virtual memory wrappers. More...

#include "base/base_types.h"
Include dependency graph for mem_os.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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

Operating System virtual memory wrappers.

Provides a unified cross-platform API for interacting directly with OS memory pages, without using the C standard library's malloc/free.

This is the lowest layer of the memory subsystem. Higher-level allocators (e.g., the Arena) call these functions internally most application code should not need to call them directly.

Reserve vs Commit
Virtual memory operates in two phases:
  • Reserve: Claims a range of virtual address space from the OS. Uses no physical RAM and is near-instant regardless of size. Think of it as "calling dibs" on addresses.
  • Commit: Maps physical RAM (or page-file space) to a sub-range of a previously reserved block. Only committed pages can be read or written.

This separation allows arenas to reserve gigabytes of address space upfront (cheap), then commit only the pages they actually use (expensive).

Definition in file mem_os.h.