Skip to content

Make ring buffer size configurable at compile time via LATTE_BUFFER_PWR #13

Description

@fior512

Motivation

The buffer size is hardcoded as BUFFER_PWR = 16 (65 536 samples per ID per thread). This is a poor fit for two common situations:

  • Embedded / constrained systems: 65 536 × 8 bytes = 512 KB per ID per thread is too much. A game running 10 IDs on 8 threads uses 40 MB just for Latte.
  • Long-running stress tests: users want to capture millions of samples without wrap-around, requiring a larger buffer.

Proposed Change

// User defines before including the header (optional):
// #define LATTE_BUFFER_PWR 20   // 1M samples

#ifndef LATTE_BUFFER_PWR
  #define LATTE_BUFFER_PWR 16   // default: 65 536
#endif

static constexpr size_t BUFFER_PWR      = LATTE_BUFFER_PWR;
static constexpr size_t MAX_SAMPLES     = 1ULL << BUFFER_PWR;
static constexpr size_t BUFFER_MASK     = MAX_SAMPLES - 1;

A static_assert(LATTE_BUFFER_PWR >= 4 && LATTE_BUFFER_PWR <= 24, ...) guards against nonsensical values.

Acceptance Criteria

  • LATTE_BUFFER_PWR respected when defined before #include "Latte.hpp"
  • Default behaviour unchanged (power = 16)
  • static_assert with a clear message for out-of-range values
  • Memory usage table added to README (power → bytes per ID per thread)
  • speedtest.cpp and testcase.cpp still compile and pass at default power

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions