orca/src/platform/win32_memory.c

45 lines
1.2 KiB
C
Raw Normal View History

2023-09-07 12:51:48 +00:00
/*************************************************************************
*
2023-09-07 12:51:48 +00:00
* Orca
* Copyright 2023 Martin Fouilleul and the Orca project contributors
* See LICENSE.txt for licensing information
*
2023-09-07 12:51:48 +00:00
**************************************************************************/
2022-12-22 17:24:43 +00:00
#define WIN32_LEAN_AND_MEAN
2023-08-19 12:49:23 +00:00
#include "platform_memory.h"
#include <windows.h>
void* oc_base_reserve_win32(oc_base_allocator* context, u64 size)
{
2023-08-19 12:49:23 +00:00
void* result = VirtualAlloc(0, size, MEM_RESERVE, PAGE_READWRITE);
return (result);
}
void oc_base_commit_win32(oc_base_allocator* context, void* ptr, u64 size)
{
2023-08-19 12:49:23 +00:00
VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE);
}
void oc_base_release_win32(oc_base_allocator* context, void* ptr, u64 size)
{
2023-08-19 12:49:23 +00:00
VirtualFree(ptr, size, MEM_RELEASE);
}
void oc_base_decommit_win32(oc_base_allocator* context, void* ptr, u64 size)
{
2023-08-19 12:49:23 +00:00
VirtualFree(ptr, size, MEM_DECOMMIT);
}
oc_base_allocator* oc_base_allocator_default()
{
2023-08-19 12:49:23 +00:00
static oc_base_allocator base = { 0 };
if(base.reserve == 0)
{
base.reserve = oc_base_reserve_win32;
base.commit = oc_base_commit_win32;
base.decommit = oc_base_decommit_win32;
base.release = oc_base_release_win32;
}
return (&base);
}