| 143 | |
| 144 | |
| 145 | long cpu_getPageSize() { |
| 146 | |
| 147 | // avoid repeated queries to this fixed value |
| 148 | static long pageSize = 0; |
| 149 | if (pageSize > 0) |
| 150 | return pageSize; |
| 151 | |
| 152 | // obtain pageSize for the first time |
| 153 | #if defined(_WIN32) |
| 154 | SYSTEM_INFO sysInfo; |
| 155 | GetSystemInfo(&sysInfo); |
| 156 | pageSize = sysInfo.dwPageSize; |
| 157 | #else |
| 158 | pageSize = sysconf(_SC_PAGESIZE); |
| 159 | #endif |
| 160 | |
| 161 | // rigorously check the found pagesize is valid |
| 162 | // and consistent with preconditions assumed by |
| 163 | // callers, to avoid extremely funky bugs on |
| 164 | // esoteric future systems |
| 165 | |
| 166 | if (pageSize <= 0) |
| 167 | error_gettingPageSizeFailed(); |
| 168 | |
| 169 | if (!isPowerOf2(pageSize)) |
| 170 | error_pageSizeNotAPowerOf2(); |
| 171 | |
| 172 | if (pageSize % sizeof(qcomp) != 0) |
| 173 | error_pageSizeNotAMultipleOfQcomp(); |
| 174 | |
| 175 | return pageSize; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | qcomp* cpu_allocArray(qindex length) { |
no test coverage detected