siddharthmittal13 opened a new pull request, #590:
URL: https://github.com/apache/avro-rs/pull/590

   ## What
   
   Closes #589.
   
   Adds an **opt-in** cargo feature `custom_allocator` (off by default) that 
exposes a new `apache_avro::alloc` module with two custom `GlobalAlloc` 
implementations:
   
   1. **`CustomAllocator`** — a minimal allocator that delegates every 
operation to the `System` allocator. A ready-made base users can install 
directly as `#[global_allocator]` or extend to add their own behavior (logging, 
pooling, ...) without reimplementing platform allocation logic.
   2. **`CountingAllocator<A = System>`** — wraps any inner allocator (defaults 
to `System`) and tracks:
      - live bytes — `allocated()`
      - high-water mark — `peak_allocated()`
      - cumulative bytes — `total_allocated()`
      - allocation / deallocation counts
      - `reset_peak()` for scoped measurement
   
      `const fn` constructors (`CountingAllocator::system()`, 
`CountingAllocator::new(inner)`) let it back a `#[global_allocator]` static.
   
   ## Why
   
   `apache-avro` currently offers no first-class hook for customizing or 
observing heap allocation. The existing `util::max_allocation_bytes` guard only 
rejects a *single* oversized length prefix at decode time — it gives no 
visibility into the actual live/peak memory a workload uses, and no reusable 
building block for custom allocation behavior.
   
   `CountingAllocator` complements `max_allocation_bytes` by measuring real 
process memory, including pressure that builds up across many 
individually-small allocations.
   
   ## Notes
   
   - **Fully opt-in / zero cost when disabled.** The module is gated behind the 
`custom_allocator` feature and is inert unless the user installs one of the 
types as their `#[global_allocator]`. The default build is unchanged.
   - Counters use relaxed atomics (observability, not hard real-time 
accounting).
   
   ## Testing
   
   - New unit tests for `CustomAllocator` (delegation) and `CountingAllocator` 
(alloc/dealloc, peak high-water mark, `reset_peak`, realloc growth/shrink) — 
all passing.
   - Both module doc examples compile (`--doc`).
   - `cargo fmt` and `cargo clippy --features custom_allocator --lib` are clean.
   - Default (feature-off) build verified.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to