src/allocator.c

changeset 1539
2cbdb482d325
parent 1395
395ad9f8da44
child 1540
411cf6fd268f
equal deleted inserted replaced
1538:fd948e5af26e 1539:2cbdb482d325
29 #include "cx/allocator.h" 29 #include "cx/allocator.h"
30 30
31 #include <errno.h> 31 #include <errno.h>
32 #include <string.h> 32 #include <string.h>
33 33
34 #ifdef _WIN32
35 #include <Windows.h>
36 #include <sysinfoapi.h>
37 unsigned long system_page_size(void) {
38 static unsigned long ps = 0;
39 if (ps == 0) {
40 SYSTEM_INFO sysinfo;
41 GetSystemInfo(&sysinfo);
42 ps = (unsigned long) sysinfo.dwPageSize;
43 }
44 return ps;
45 }
46 #else
47 #include <unistd.h>
48 unsigned long system_page_size(void) {
49 static unsigned long ps = 0;
50 if (ps == 0) {
51 long sc = sysconf(_SC_PAGESIZE);
52 if (sc < 0) {
53 // fallback for systems which do not report a value here
54 ps = 4096; // LCOV_EXCL_LINE
55 } else {
56 ps = (unsigned long) sc;
57 }
58 }
59 return ps;
60 }
61 #endif
62
34 static void *cx_malloc_stdlib( 63 static void *cx_malloc_stdlib(
35 cx_attr_unused void *d, 64 cx_attr_unused void *d,
36 size_t n 65 size_t n
37 ) { 66 ) {
38 return malloc(n); 67 return malloc(n);

mercurial