Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Allocator ¶
type Allocator interface { // Malloc allocates a slab of memory of argument number of bytes. // The pointer returned points to the start address of the slab. // If the memory fails to allocate then nil is returned. Malloc(sizeInBytes int) unsafe.Pointer // Free receives a point previously allocated by Malloc and frees it. // After the memory is freed the pointer should be discarded and no other operation done with it. Free(toBeFreed unsafe.Pointer) error }
Allocator is the interface of a manual memory allocator.
type TestAllocator ¶
type TestAllocator struct {
// contains filtered or unexported fields
}
TestAllocator is a simple implementation of an Allocator. It has the added complexity of being able to reuse freed memory later on to potentially detect use-after-free and double-free bugs.
func (*TestAllocator) Free ¶
func (a *TestAllocator) Free(p unsafe.Pointer) error
Free implements [Allocator.Free].
func (*TestAllocator) Malloc ¶
func (a *TestAllocator) Malloc(n int) unsafe.Pointer
Malloc implements [Allocator.Malloc].
func (*TestAllocator) SetMaxFree ¶
func (a *TestAllocator) SetMaxFree(maxFreeMemInBytes int)
SetMaxFree sets the maximum amount of freed memory to have allocated and ready for reuse. Set to zero for limitless memory. Set to -1 to disable freed memory reuse.
func (*TestAllocator) SetMaxMemory ¶
func (a *TestAllocator) SetMaxMemory(maxmemInBytes int)
SetMaxMemory sets the maximum amount of memory the allocator can have allocated, combined between live and freed. Set to zero to disable memory limits.
func (*TestAllocator) SetOnFreeCallback ¶
func (a *TestAllocator) SetOnFreeCallback(onFree func(b []byte))
SetOnFreeCallback is called on TestAllocator.Free argument buffer after it successfully finds the memory to free.