| 179 | } |
| 180 | |
| 181 | void* os_malloc(size_t bytes, bool& hugepages) |
| 182 | { |
| 183 | if (bytes == 0) { |
| 184 | hugepages = false; |
| 185 | return nullptr; |
| 186 | } |
| 187 | |
| 188 | /* try direct huge page allocation first */ |
| 189 | if (isHugePageCandidate(bytes)) |
| 190 | { |
| 191 | int flags = MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES; |
| 192 | char* ptr = (char*) VirtualAlloc(nullptr,bytes,flags,PAGE_READWRITE); |
| 193 | if (ptr != nullptr) { |
| 194 | hugepages = true; |
| 195 | return ptr; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /* fall back to 4k pages */ |
| 200 | int flags = MEM_COMMIT | MEM_RESERVE; |
| 201 | char* ptr = (char*) VirtualAlloc(nullptr,bytes,flags,PAGE_READWRITE); |
| 202 | if (ptr == nullptr) throw std::bad_alloc(); |
| 203 | hugepages = false; |
| 204 | return ptr; |
| 205 | } |
| 206 | |
| 207 | size_t os_shrink(void* ptr, size_t bytesNew, size_t bytesOld, bool hugepages) |
| 208 | { |
no test coverage detected