Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Linkable ¶
type Linkable[T any] interface { Next() T SetNext(T) }
Linkable defines the requirements for an item to be managed by the Pool. T represents the pointer to the item (e.g., *MyStruct).
type Pool ¶
type Pool[E any, P interface { *E Linkable[P] }] struct { // New optionally specifies a function to generate // a value when Get would otherwise return nil. // It may not be changed concurrently with calls to Get. New func() P // contains filtered or unexported fields }
Pool is a lock-free (per-P) pool of objects. Objects in the pool never expire.
The objects must implement the Linkable interface (with a pointer receiver.
Example:
type MyObject struct {
ID int
next *MyObject
}
func (o *MyObject) Next() *MyObject { return o.next }
func (o *MyObject) SetNext(next *MyObject) { o.next = next }
Synchronization is done using runtime.procPin/runtime.procUnpin.
It take two opera types: E: The struct type (e.g., UserObject) P: The pointer type (e.g., *UserObject)
The constraint `interface { *E; Linkable[P] }` enforces that: 1. P is exactly a pointer to E (*E) 2. P implements Linkable for itself