53 lines
895 B
C++
53 lines
895 B
C++
|
|
#include "variant_pool.hpp"
|
|
|
|
#include <cassert>
|
|
|
|
namespace vk_capture
|
|
{
|
|
|
|
//
|
|
// internal defines
|
|
//
|
|
|
|
//
|
|
// internal constants
|
|
//
|
|
|
|
//
|
|
// internal types
|
|
//
|
|
|
|
//
|
|
// internal variables
|
|
//
|
|
|
|
//
|
|
// internal functions
|
|
//
|
|
|
|
//
|
|
// public functions
|
|
//
|
|
|
|
VkVariantMWN* VariantPool::allocate(std::size_t num)
|
|
{
|
|
assert(num > 0 && num <= PAGE_SIZE);
|
|
const std::size_t remainingOnPage = PAGE_SIZE - (nextIndex % PAGE_SIZE);
|
|
const std::size_t page = nextIndex / PAGE_SIZE;
|
|
const std::size_t localIndex = nextIndex % PAGE_SIZE;
|
|
if (remainingOnPage == PAGE_SIZE || remainingOnPage < num)
|
|
{
|
|
// next page
|
|
if (page + 1 >= pages.size()) {
|
|
pages.push_back(std::make_unique<page_t>());
|
|
}
|
|
nextIndex = PAGE_SIZE * (pages.size() - 1);
|
|
}
|
|
VkVariantMWN* result = &(*pages[page])[localIndex];
|
|
nextIndex += num;
|
|
return result;
|
|
}
|
|
|
|
} // namespace v
|