31 lines
1.0 KiB
C++
31 lines
1.0 KiB
C++
#include <algorithm>
|
|
#include <cstdlib>
|
|
#include <cassert>
|
|
#include <new>
|
|
#include <bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp>
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#include <Windows.h>
|
|
|
|
namespace BGTU::ComputerGraphicsLabWork::Utilities {
|
|
DefaultVoxelDrawerCache::ZElementAllocationBuffer::Page *DefaultVoxelDrawerCache::ZElementAllocationBuffer::_native_extend() {
|
|
SYSTEM_INFO si;
|
|
GetSystemInfo(&si);
|
|
|
|
std::size_t size = max(si.dwPageSize, si.dwAllocationGranularity);
|
|
|
|
void *raw = VirtualAlloc(nullptr, max(si.dwPageSize, si.dwAllocationGranularity), MEM_COMMIT, PAGE_READWRITE);
|
|
if (raw == nullptr) throw std::bad_alloc{};
|
|
this->last_allocated_page->next = new(raw)Page(nullptr, Page::calc_capacity(size));
|
|
return this->last_allocated_page = this->last_allocated_page->next;
|
|
}
|
|
|
|
|
|
void DefaultVoxelDrawerCache::ZElementAllocationBuffer::_native_free_page(DefaultVoxelDrawerCache::ZElementAllocationBuffer::Page *p) {
|
|
VirtualFree(p, 0, MEM_DECOMMIT | MEM_RELEASE);
|
|
}
|
|
}
|
|
#else
|
|
# error ""
|
|
#endif |