|
Leka
A low-latency C++20 price-time-priority limit order book and matching engine
|
Provides stable, pooled storage for Order objects. More...
#include <order_pool.hpp>
Classes | |
| struct | Page |
Public Member Functions | |
| OrderPool () | |
| Creates an empty pool without allocating a page. | |
| OrderPool (OrderPool &&)=delete | |
| OrderPool & | operator= (OrderPool &&)=delete |
| OrderPool (const OrderPool &)=delete | |
| OrderPool & | operator= (const OrderPool &)=delete |
| ~OrderPool () | |
| Destroys all live orders and releases every allocated page. | |
| Order * | allocate (OrderId orderId, Price price, Quantity originalQuantity, Timestamp timestamp, OrderSide orderSide, OrderType orderType, SequenceNumber sequenceNumber) |
| Constructs an Order in a stable pool slot. | |
| Order * | allocate (OrderId orderId, Price price, Quantity originalQuantity, Quantity remainingQuantity, Timestamp timestamp, OrderSide orderSide, OrderType orderType, SequenceNumber sequenceNumber) |
| Constructs an Order with explicit original and remaining quantities. | |
| void | release (Order *order) |
| Destroys an order and returns its slot to the free list. | |
| void | reserve (std::size_t orderCount) |
Pre-allocates enough pages to hold at least orderCount live orders without allocate() creating a page on its own. | |
| std::size_t | getPageCount () const |
| Returns the number of allocated pages. | |
| std::size_t | getLiveOrderCount () const |
| Returns the number of live orders in the pool. | |
Static Public Attributes | |
| static constexpr std::size_t | PageSize = 64 * 1024 |
| static constexpr std::size_t | SlotsPerPage = PageSize / sizeof(Order) |
Provides stable, pooled storage for Order objects.
Storage is allocated in fixed 64 KiB pages. Orders are constructed in place, never compacted, and released slots are reused without moving live orders.
Definition at line 23 of file order_pool.hpp.
|
default |
Creates an empty pool without allocating a page.
References allocate(), OrderPool(), release(), and reserve().
Referenced by OrderPool().
| lob::OrderPool::~OrderPool | ( | ) |
Destroys all live orders and releases every allocated page.
Definition at line 75 of file order_pool.cpp.
| Order * lob::OrderPool::allocate | ( | OrderId | orderId, |
| Price | price, | ||
| Quantity | originalQuantity, | ||
| Timestamp | timestamp, | ||
| OrderSide | orderSide, | ||
| OrderType | orderType, | ||
| SequenceNumber | sequenceNumber ) |
Constructs an Order in a stable pool slot.
Definition at line 137 of file order_pool.cpp.
References allocate().
Referenced by allocate(), and OrderPool().
| Order * lob::OrderPool::allocate | ( | OrderId | orderId, |
| Price | price, | ||
| Quantity | originalQuantity, | ||
| Quantity | remainingQuantity, | ||
| Timestamp | timestamp, | ||
| OrderSide | orderSide, | ||
| OrderType | orderType, | ||
| SequenceNumber | sequenceNumber ) |
Constructs an Order with explicit original and remaining quantities.
Definition at line 144 of file order_pool.cpp.
| void lob::OrderPool::release | ( | Order * | order | ) |
Destroys an order and returns its slot to the free list.
Releases a live slot after validating pool ownership and allocation state.
Definition at line 183 of file order_pool.cpp.
Referenced by OrderPool().
| void lob::OrderPool::reserve | ( | std::size_t | orderCount | ) |
Pre-allocates enough pages to hold at least orderCount live orders without allocate() creating a page on its own.
A page is created lazily, on the first allocate() call that finds no free slot, via mmap — a syscall with a genuinely unbounded tail (page fault handling, kernel scheduling), which is why it shows up as the multi-order-of-magnitude outliers in a latency histogram (see ARCH_DECISIONS.md ADR-008). Calling this once, before trading begins, for a known or comfortably over-estimated maximum order count moves every one of those mmap calls out of the hot path entirely, the same trade PriceLadder already makes for price levels: pay a bounded, known cost once, in exchange for a flat tail afterward. Exceeding orderCount still falls back to the lazy per-allocation behavior rather than failing.
Only ever creates pages, never removes them: reserving a smaller count than a previous call is a no-op rather than shrinking capacity that may already hold live orders.
Definition at line 175 of file order_pool.cpp.
Referenced by OrderPool().
|
inline |
Returns the number of allocated pages.
Definition at line 71 of file order_pool.hpp.
|
inline |
Returns the number of live orders in the pool.
Definition at line 73 of file order_pool.hpp.
|
staticconstexpr |
Definition at line 25 of file order_pool.hpp.
|
staticconstexpr |
Definition at line 26 of file order_pool.hpp.