Documentation
¶
Index ¶
- type Ring
- func (r *Ring) Advance(n uintptr) error
- func (r *Ring) Close() error
- func (r *Ring) Consume(n uintptr) error
- func (r *Ring) Content() []byte
- func (r *Ring) Init(size uintptr) (err error)
- func (r *Ring) Read(f func(buffer []byte) (consumed uintptr, err error)) (consumed uintptr, err error)
- func (r *Ring) Size() uintptr
- func (r *Ring) Unused() []byte
- func (r *Ring) Write(f func(buffer []byte) (newData uintptr, err error)) (newData uintptr, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
func (*Ring) Advance ¶
Advance bumps the head, in other words it tells the ring that you have written to the slice returned by .Unused.
func (*Ring) Close ¶
Close frees up the mmaped memory and must be manually called before the Ring is garbage collected. Very important, any buffer returned by .Context or .Unused, or leaked from .Write or .Read will become invalid and point to who knows what and cannot be used. If you *retain* theses buffers, you might need to set them to nil before calling Close.
func (*Ring) Content ¶
Content returns a single contiguous slice of the content in the ring so you can pass it to os.File.Write or whatever is gonna read from it. It returns a byte slice that is only valid before calling Ring.Close, you should avoid retaining this slice and might need to manually nil it out before calling Close to avoid the GC attempting to scan unmapped memory.
func (*Ring) Read ¶
func (r *Ring) Read(f func(buffer []byte) (consumed uintptr, err error)) (consumed uintptr, err error)
Read is an alternative to Content and Consume, you get called back with a reference to the used buffer and return how many bytes you have consumed. The passed-in slice is not valid once f returns.
func (*Ring) Unused ¶
Unused returns a single contiguous slice of unused memory in the ring so you can pass it to os.File.Read or whatever is gonna write to it. It returns a byte slice that is only valid before calling Ring.Close, you should avoid retaining this slice and might need to manually nil it out before calling Close to avoid the GC attempting to scan unmapped memory.
func (*Ring) Write ¶
func (r *Ring) Write(f func(buffer []byte) (newData uintptr, err error)) (newData uintptr, err error)
Write is an alternative to Unused and Advance, you get called back with a reference to the unused buffer and return how many new bytes are there. The passed-in slice is not valid once f returns.