PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
cache_capacity.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6#include <limits>
7
8namespace pineforge {
9
10// An inclusive allowance for optional cache lines. Geometry, fixed control
11// state and mandatory transfer/transaction workspace belong to the store.
13 std::size_t capacity_bytes = 0;
14
15 // Compatibility for constructors expressed in payload bytes. Reserve the
16 // shared line charge once, preserving every complete legacy payload page.
17 static CacheCapacity from_payload(std::size_t page_size,
18 std::size_t payload_bytes) noexcept {
19 const auto charged = detail::ReadThroughCache::line_bytes(page_size);
20 const auto count = page_size ? payload_bytes / page_size : 0;
21 return charged && count <= std::numeric_limits<std::size_t>::max() / charged
22 ? CacheCapacity{count * charged} : CacheCapacity{};
23 }
24
25 detail::ReadThroughCachePolicy for_page(std::size_t page_size) const noexcept {
26 return {capacity_bytes, page_size};
27 }
28
29 std::size_t lines(std::size_t page_size) const noexcept {
30 const auto charged = detail::ReadThroughCache::line_bytes(page_size);
31 return charged == 0 ? 0 : capacity_bytes / charged;
32 }
33 // Bridge for adapters whose constructor still accepts payload bytes. The
34 // common line charge has already been reserved, so payload never exceeds
35 // the inclusive host allowance. Common-cache adapters use for_page().
36 std::size_t payload_bytes(std::size_t page_size) const noexcept {
37 return lines(page_size) * page_size;
38 }
39};
40
41} // namespace pineforge
static std::size_t line_bytes(std::size_t page_size) noexcept
detail::ReadThroughCachePolicy for_page(std::size_t page_size) const noexcept
std::size_t payload_bytes(std::size_t page_size) const noexcept
std::size_t lines(std::size_t page_size) const noexcept
static CacheCapacity from_payload(std::size_t page_size, std::size_t payload_bytes) noexcept