bresenham-0.rs/utilities/src/memory_pages_managment.cpp

29 lines
937 B
C++

#include <bgtu/computer_graphics_lab_work/utilities/default_renderer_linear.hpp>
#if defined(_WIN32)
#include <cstdlib>
#include <cassert>
#include <new>
#include <Windows.h>
namespace BGTU::ComputerGraphicsLabWork::Utilities {
DefaultVoxelDrawerLinear::ZElementAllocationBuffer::Page *DefaultVoxelDrawerLinear::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{};
return this->last_page = new(raw)Page(this->last_page, Page::calc_capacity(size));
}
void DefaultVoxelDrawerLinear::ZElementAllocationBuffer::_native_free_page(DefaultVoxelDrawerLinear::ZElementAllocationBuffer::Page *p) {
VirtualFree(p, 0, MEM_DECOMMIT | MEM_RELEASE);
}
}
#else
# error ""
#endif