You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, response buffer allocation was hardcoded with an internal
pooler implementation. Users had no control over memory management
for responses, which could be problematic for applications with
specific memory requirements or custom allocation strategies.
The new Allocator interface allows users to implement custom buffer
allocation and reuse strategies:
```
// Allocator is an interface for allocating and deallocating byte
// slices.
type Allocator interface {
// Get returns a pointer to a byte slice of at least the given
// length.
// The caller should not assume anything about the slice's
// capacity.
//
// If the allocator cannot allocate a buffer (e.g., invalid
// length), it returns nil. The caller must handle this case
// appropriately.
Get(length int) *[]byte
// Put returns a byte slice to the allocator for reuse.
// After calling Put, the caller must not use the slice.
//
// The caller must ensure that the slice length remains unchanged
// between Get and Put calls. Modifying the slice length before
// calling Put may prevent the allocator from properly reusing the
// buffer.
Put(buf *[]byte)
}
```
The PoolAllocator type provides a ready-to-use implementation based
on sync.Pool for power-of-two sized byte slices.
The Opts.Allocator option enables configuring a custom allocator
for a connection. This is useful for applications that need to
optimize memory usage or integrate with custom memory management
systems.
Closes#493
0 commit comments