1
0
Fork 0

Added: Win32 platform layer

Browse Source
This commit is contained in:
rhuibertsjr 2024-04-25 19:33:44 +02:00
parent 55632d07eb
commit 792ddeb80d
2 changed files with 51 additions and 0 deletions

34
src/win32_platform.c Normal file
View File

@ -0,0 +1,34 @@
internal void *
platform_memory_reserve(u64 size)
{
void *result = VirtualAlloc(0, size, MEM_RESERVE, PAGE_READWRITE);
return result;
}
internal b8
platform_memory_commit(void *ptr, u64 size)
{
b32 result = (VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE) != 0);
return result;
}
internal void
platform_memory_decommit(void *ptr, u64 size)
{
VirtualFree(ptr, size, MEM_DECOMMIT);
};
internal void
platform_memory_release(void *ptr, u64 size)
{
VirtualFree(ptr, 0, MEM_RELEASE);
}
internal u64
platform_get_page_size(void)
{
SYSTEM_INFO sysinfo = {0};
GetSystemInfo(&sysinfo);
return sysinfo.dwPageSize;
}

17
src/win32_platform.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef WIN32_PLATFORM_H
#define WIN32_PLATFORM_H
#undef internal
#include <Windows.h>
#define internal static
//= rhjr: platform memory management
internal void * platform_memory_reserve(u64 size);
internal b8 platform_memory_commit(void *ptr, u64 size);
internal void platform_memory_decommit(void *ptr, u64 size);
internal void platform_memory_release(void *ptr, u64 size);
internal u64 platform_get_page_size(void);
#endif // WIN32_PLATFORM_H