1 #pragma once
2 
3 #ifdef _MSC_VER
4 #include <malloc.h>
5 #include <Windows.h>
6 #else
7 #include <stdlib.h>
8 #include <unistd.h>
9 #endif
10 
11 #include "maybe_unused.h"
12 
13 FRAMEWORK_MAYBE_UNUSED
framework_getpagesize()14 static size_t framework_getpagesize()
15 {
16 #if defined(_MSC_VER)
17 	SYSTEM_INFO si;
18 	GetSystemInfo(&si);
19 	return si.dwPageSize;
20 #else
21 	return sysconf(_SC_PAGESIZE);
22 #endif
23 }
24 
25 FRAMEWORK_MAYBE_UNUSED
framework_aligned_alloc(size_t allocSize,size_t alignment)26 static void* framework_aligned_alloc(size_t allocSize, size_t alignment)
27 {
28 #if defined(_MSC_VER)
29 	return _aligned_malloc(allocSize, alignment);
30 #elif defined(__ANDROID__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__linux__)
31 	void* result = nullptr;
32 	if(posix_memalign(&result, alignment, allocSize) != 0)
33 	{
34 		return nullptr;
35 	}
36 	return result;
37 #else
38 	return malloc(allocSize);
39 #endif
40 }
41 
42 FRAMEWORK_MAYBE_UNUSED
framework_aligned_free(void * ptr)43 static void framework_aligned_free(void* ptr)
44 {
45 #if defined(_MSC_VER)
46 	_aligned_free(ptr);
47 #else
48 	free(ptr);
49 #endif
50 }
51