Memory Types

The Memory Package provides two memory types optimized for different scenarios.

FixedMemory

Memory with a permanently bound segment, allocated from slab pools.

public final class FixedMemory extends AbstractMemory {
    private final MemorySegment segment;  // Final - never changes
    
    public FixedMemory(MemorySegment segment);
}

Characteristics

  • Segment bound once at construction, never rebound

  • Data boundaries (start/end) are mutable for headroom/tailroom

  • Used with pools for packet buffers that persist

Lifecycle

Pool Creation:
    SlabAllocator allocates bulk memory

    new FixedMemory(segment)  ← Bound permanently

    Added to pool free-list

Hot Path:
    pool.allocate() → FixedMemory

    Reset start/end bounds only (NO rebinding)

    Use for packet processing

    packet.recycle() → back to free-list

When to Use

  • Pool-allocated packet buffers

  • Copied packet data that outlives native buffers

  • Any scenario where memory persists across operations

ScopedMemory

Memory wrapper for externally-provided segments from native backends.

Characteristics

  • Segment can be rebound to different native memory

  • Used for zero-copy packet processing

  • Bind/unbind cycle per packet in capture path

Zero-Copy Pattern

When to Use

  • Zero-copy capture from DPDK, Napatech, etc.

  • When packet data doesn't need to persist

  • Maximum performance scenarios

Comparison

Aspect
FixedMemory
ScopedMemory

Segment

Final, never changes

Rebindable

Allocation

From slab pools

External (native backend)

Hot path

Bounds reset only

Full bind/unbind

Use case

Copied packets

Zero-copy capture

Persistence

Data persists

Data transient

AbstractMemory Base Class

Both types extend AbstractMemory which provides:

PoolEntry Integration

Both memory types implement Poolable:

This enables seamless pool integration - memory objects can be recycled without affecting their bound segments (for FixedMemory) or can have segments unbound (for ScopedMemory).

Last updated