summaryrefslogtreecommitdiffstats
path: root/source/base/base_stack_win32.cpp
blob: a5a4b31212d10aff050eed186994edaacc493f4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// request a page from the operating system
internal MemStack *win32_stack_create(u64 capacity)
{
 MemStack *stack = (MemStack *)VirtualAlloc(NULL, capacity + sizeof(MemStack),
                                            MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);

 if(!stack) {
  Log("Failed to receive a memory address from the operating system");
  return NULL;
 }

 stack->capacity       = capacity;
 stack->base_position  = (u8 *)stack + sizeof(MemStack);
 stack->current_offset = 0;
 return stack;
}

internal void win32_stack_destroy(MemStack *stack)
{
 b32 result = VirtualFree(stack,
                          0, // stands for the byte of committed pages
                          MEM_RELEASE);

 if(!result) {
  Log("Failed to receive a memory address from the operating system");
 }
}