Documentation ¶
Overview ¶
Package padded provides a padded byte slice and pool allocator.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool implements a memory pool for padded byte slices. Both the capacity and padding are reclaimed when a slice is freed.
type Slice ¶
type Slice []byte
Slice is a padded byte slice. The padding is a scratch space allocated in front of byte slice and behaves roughly the same as the capacity. The len & cap built-in funcs work the same for Slice as for []byte, but append does not. Use the Append method instead.
Prepending elements to the slice fills in the padding, just as appending elements to the slice fills in the capacity. The elements must be naturally aligned to fill in the scratch padding, otherwise an append is performed. The word size on an amd64 machine is 8 bytes, so element bytes should be prepended in multiples of 8.
func Make ¶
Make allocates and initializes a padded byte slice. Unlike cap, the pad value is only the size of the scratch space in front of the slice. (The scratch space in back is cap - len.)
The allocated scratch space for padding may be >= pad.
func (Slice) Append ¶
Append appends elements to the end of s. The behavior of Append is the same as the built-in append function.