Documentation
¶
Index ¶
- Constants
- Variables
- func AlignDown(value int, alignment uint) int
- func AlignUp(value int, alignment uint) int
- func CheckPow2[T Number](number T, name string) error
- func DebugCheckPow2(value uint, name string)
- func DebugValidate(validatable Validatable)
- func ValidateMagicValue(data unsafe.Pointer, offset int) bool
- func WriteMagicValue(data unsafe.Pointer, offset int)
- type DetailedStatistics
- type Number
- type Statistics
- type Validatable
Constants ¶
const ( // DebugMargin is the number of bytes of debug data that should be placed between allocations in blocks managed // by memutils DebugMargin int = 0 )
Variables ¶
var PowerOfTwoError error = errors.New("number must be a power of two")
PowerOfTwoError is the error returned from CheckPow2 or other methods if the number being tested is not a power of two
Functions ¶
func AlignDown ¶
AlignDown will reduce the provided value until it matches the provided alignment, if necessary, and returns the reduced value.
func AlignUp ¶
AlignUp will increase the provided value until it matches the provided alignment, if necessary, and returns the increased value.
func CheckPow2 ¶
CheckPow2 verifies whether the provided number is a power of 2 and returns an error if not- the name will be used to identify the non-power-of-two number in the error message for convenience
func DebugCheckPow2 ¶
DebugCheckPow2 will verify that the numerical value passed in is a power of two, and panics if it is not. This method no-ops unless the debug_mem_utils build tag is present.
func DebugValidate ¶
func DebugValidate(validatable Validatable)
DebugValidate will call Validate on the provided object and panics if any errors are returned. This method no-ops unless the debug_mem_utils build tag is present
func ValidateMagicValue ¶
ValidateMagicValue verifies that the easy-to-identify marker written by WriteMagicValue is still present. It returns true if the value is still present and false otherwise. This method no-ops unless the debug_mem_utils build tag is present.
func WriteMagicValue ¶
WriteMagicValue writes an easy-to-identify marker across DebugMargin bytes at the provided pointer and offset. This method no-ops unless the debug_mem_utils build tag is present.
Types ¶
type DetailedStatistics ¶
type DetailedStatistics struct { Statistics // UnusedRangeCount is the number of contiguous regions of free space in the pool UnusedRangeCount int // AllocationSizeMin is the size, in bytes, of the smallest allocation in the pool AllocationSizeMin int // AllocationSizeMax is the size, in bytes, of the largest allocation in the pool AllocationSizeMax int // UnusedRangeSizeMin is the size, in bytes, of the smallest contiguous region of free space in the pool UnusedRangeSizeMin int // UnusedRangeSizeMax is the size, in bytes, of the largest contiguous region of free space in the pool UnusedRangeSizeMax int }
DetailedStatistics is a superset of Statistics that includes additional fields
func (*DetailedStatistics) AddAllocation ¶
func (s *DetailedStatistics) AddAllocation(size int)
AddAllocation adds an allocation to this object's metrics
size - The size, in bytes, of the allocation
func (*DetailedStatistics) AddDetailedStatistics ¶
func (s *DetailedStatistics) AddDetailedStatistics(other *DetailedStatistics)
AddDetailedStatistics sums another DetailedStatistics object's metrics into this DetailedStatistics object
func (*DetailedStatistics) AddUnusedRange ¶
func (s *DetailedStatistics) AddUnusedRange(size int)
AddUnusedRange adds a contiguous region of free space to this object's metrics
size - The size, in bytes, of the region
func (*DetailedStatistics) Clear ¶
func (s *DetailedStatistics) Clear()
Clear zeroes out all metrics
func (*DetailedStatistics) PrintJson ¶
func (s *DetailedStatistics) PrintJson(writer *jwriter.Writer)
PrintJson writes a json object that contains this object's metrics
type Statistics ¶
type Statistics struct { // The number of memory pages active in the pool BlockCount int // The number of allocations that have been assigned in the pool AllocationCount int // The number of bytes that are in all memory pages in the pool BlockBytes int // The number of bytes in the pool that have been assigned to allocations. Free bytes // are not counted AllocationBytes int }
Statistics is a type that represents metrics for the current state of a memory pool
func (*Statistics) AddStatistics ¶
func (s *Statistics) AddStatistics(other *Statistics)
AddStatistics sums another Statistics object's metrics into this Statistics object
func (*Statistics) PrintJson ¶
func (s *Statistics) PrintJson(writer *jwriter.Writer)
PrintJson writes a json object that contains this object's metrics
type Validatable ¶
type Validatable interface {
Validate() error
}