PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
cache_policy.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <cstddef>
8#include <limits>
9
10namespace pineforge {
11
12// Per-owner physical policy, copied at admission and never folded into
13// continuation state. Zero bypasses the optional cache. Except for the ledger
14// setting below, sub-line allowances also bypass. Allowances include metadata.
15// Defaults preserve the old payload line counts and add their exact common
16// cache tag/pin/replacement charge. Fixed workspace is accounted separately.
18 static CacheCapacity lines(std::size_t page_size, std::size_t count) {
19 if (count == 0) return {};
20 const auto charged = detail::ReadThroughCache::line_bytes(page_size);
21 if (charged == 0 || count > std::numeric_limits<std::size_t>::max() / charged)
23 {{"input", "cache_policy"}, {"reason", "value_above_maximum"}},
24 "cache policy line geometry is not representable");
25 return {charged * count};
26 }
28
29 // The host ledger setting includes entries and the private page table.
30 // It shares the standalone conversion and retains the existing row range.
31 static std::size_t ledger_cache_rows(CacheCapacity capacity) {
32 const auto rows = TradeLedger::cache_rows_for_capacity(capacity);
33 if (capacity.capacity_bytes != 0 && rows == 0)
35 {{"input", "cache_policy"}, {"reason", "value_below_minimum"}},
36 "ledger cache capacity is below one decoded entry and page pointer");
37 if (rows > TradeLedger::kMaxCacheRows)
39 {{"input", "cache_policy"}, {"reason", "value_above_maximum"}},
40 "ledger cache capacity exceeds the existing row setting range");
41 return rows;
42 }
43
45 TradeLedger::cache_capacity_bytes(TradeLedger::kDefaultCacheRows)};
51
56
57 CacheCapacity position_tail_pages = lines(4096, 64 * 1024 / 4096);
61 CacheCapacity equity_curve_pages = lines(24, 64 * 1024 / 24);
62
63 // History keeps its existing semantic lookback. These are cache bytes,
64 // never lengths, max_bars_back, bars of input or a number of feed records.
65 CacheCapacity ta_history_pages{std::numeric_limits<std::size_t>::max()};
67 // Run default for tapes installed without an explicit C++ capacity.
70};
71
72} // namespace pineforge
Base with a code: throw coded<std::invalid_argument>(code, {args}, text).
static std::size_t line_bytes(std::size_t page_size) noexcept
CacheCapacity consumed_cycle_pages
static std::size_t ledger_cache_rows(CacheCapacity capacity)
static CacheCapacity lines(std::size_t page_size, std::size_t count)
CacheCapacity recorded_series_pages
CacheCapacity cohort_id_pages
CacheCapacity retained_sequence_pages
CacheCapacity ta_history_pages
CacheCapacity dependency_pages
CacheCapacity successor_root_pages
CacheCapacity projection_exit_pages
CacheCapacity erased_minima_pages
CacheCapacity exit_rank_pages
static CacheCapacity platform_command_pages() noexcept
CacheCapacity receipt_tail_pages
CacheCapacity feed_calendar_pages
CacheCapacity position_tail_pages
CacheCapacity equity_curve_pages
CacheCapacity chain_segment_pages