Documentation ¶
Index ¶
- Constants
- func RoundToAlign(x, align uint32) uint32
- func ZeroMem(addr uintptr, size int)
- type ArenaAllocator
- func (this *ArenaAllocator) Alloc(size uint32) (addr MemPtr, allocSize uint32)
- func (this *ArenaAllocator) AllocBytes(data []byte) MemPtr
- func (this *ArenaAllocator) AllocBytesBegin() MemPtr
- func (this *ArenaAllocator) AllocBytesEnd(addr MemPtr)
- func (this *ArenaAllocator) AllocWithClear(size uint32) (addr MemPtr, allocSize uint32)
- func (this *ArenaAllocator) AppendByte(data byte) bool
- func (this *ArenaAllocator) AppendByteNoCheck(data byte)
- func (this *ArenaAllocator) AppendBytes(data []byte) bool
- func (this *ArenaAllocator) Capacity() uint32
- func (this *ArenaAllocator) Clone() *ArenaAllocator
- func (this *ArenaAllocator) FreeAll()
- func (this *ArenaAllocator) FreePart(remain uint32)
- func (this *ArenaAllocator) GetString(addr MemPtr) string
- func (this *ArenaAllocator) GetUintptr(addr MemPtr) uintptr
- func (this *ArenaAllocator) Init(capacity uint32) *ArenaAllocator
- func (this *ArenaAllocator) Left() uint32
- func (this *ArenaAllocator) Print(w io.Writer, memBegin, memEnd int)
- func (this *ArenaAllocator) PrintAll(w io.Writer)
- func (this *ArenaAllocator) PrintBrief(w io.Writer)
- func (this *ArenaAllocator) PrintUsed(w io.Writer)
- func (this *ArenaAllocator) Stat() *ArenaAllocatorStat
- func (this *ArenaAllocator) String() string
- func (this *ArenaAllocator) Strlen(addr MemPtr) int
- func (this *ArenaAllocator) Used() uint32
- func (this *ArenaAllocator) ZeroMem(addr MemPtr, num uint32)
- type ArenaAllocatorStat
- func (this *ArenaAllocatorStat) AllocNum() StatNumber
- func (this *ArenaAllocatorStat) AllocNumOk() StatNumber
- func (this *ArenaAllocatorStat) ClearAllocNum()
- func (this *ArenaAllocatorStat) FreeAllNum() StatNumber
- func (this *ArenaAllocatorStat) FreePartNum() StatNumber
- func (this *ArenaAllocatorStat) Init()
- func (this *ArenaAllocatorStat) Print(w io.Writer)
- func (this *ArenaAllocatorStat) String() string
- type MemPtr
- type StatNumber
Constants ¶
View Source
const ( MEM_PTR_BITS = unsafe.Sizeof(MemPtr(0)) * 8 MEM_PTR_BIT = MemPtr(1 << (MEM_PTR_BITS - 1)) MEM_PTR_MASK = MemPtr(^MEM_PTR_BIT) )
View Source
const ARENA_ALLOCATOR_PREFIX_LEN = 8
View Source
const MEM_PTR_NIL = MemPtr(0)
Variables ¶
This section is empty.
Functions ¶
func RoundToAlign ¶
Types ¶
type ArenaAllocator ¶
type ArenaAllocator struct { ArenaAllocatorStat // contains filtered or unexported fields }
ArenaAllocator is a memory allocator for text/binary protocol processing,
it allocates memories and does not deallocate every memories which have been allocated. It deallacator all memories by FreeAll. ArenaAllocator has no lock, so it is not gorouting safe, each gorouting should use their own ArenaAllocator ArenaAllocator allocates memory fast and support alloctes memory when parsing. ArenaAllocator can be reused when one protocol message is processed completed.
func NewArenaAllocator ¶
func NewArenaAllocator(capacity, align uint32) *ArenaAllocator
align must be power of 2
func (*ArenaAllocator) Alloc ¶
func (this *ArenaAllocator) Alloc(size uint32) (addr MemPtr, allocSize uint32)
func (*ArenaAllocator) AllocBytes ¶
func (this *ArenaAllocator) AllocBytes(data []byte) MemPtr
func (*ArenaAllocator) AllocBytesBegin ¶
func (this *ArenaAllocator) AllocBytesBegin() MemPtr
func (*ArenaAllocator) AllocBytesEnd ¶
func (this *ArenaAllocator) AllocBytesEnd(addr MemPtr)
func (*ArenaAllocator) AllocWithClear ¶
func (this *ArenaAllocator) AllocWithClear(size uint32) (addr MemPtr, allocSize uint32)
func (*ArenaAllocator) AppendByte ¶
func (this *ArenaAllocator) AppendByte(data byte) bool
func (*ArenaAllocator) AppendByteNoCheck ¶
func (this *ArenaAllocator) AppendByteNoCheck(data byte)
func (*ArenaAllocator) AppendBytes ¶
func (this *ArenaAllocator) AppendBytes(data []byte) bool
func (*ArenaAllocator) Capacity ¶
func (this *ArenaAllocator) Capacity() uint32
func (*ArenaAllocator) Clone ¶
func (this *ArenaAllocator) Clone() *ArenaAllocator
func (*ArenaAllocator) FreeAll ¶
func (this *ArenaAllocator) FreeAll()
func (*ArenaAllocator) FreePart ¶
func (this *ArenaAllocator) FreePart(remain uint32)
func (*ArenaAllocator) GetString ¶
func (this *ArenaAllocator) GetString(addr MemPtr) string
func (*ArenaAllocator) GetUintptr ¶
func (this *ArenaAllocator) GetUintptr(addr MemPtr) uintptr
func (*ArenaAllocator) Init ¶
func (this *ArenaAllocator) Init(capacity uint32) *ArenaAllocator
func (*ArenaAllocator) Left ¶
func (this *ArenaAllocator) Left() uint32
func (*ArenaAllocator) PrintAll ¶
func (this *ArenaAllocator) PrintAll(w io.Writer)
func (*ArenaAllocator) PrintBrief ¶
func (this *ArenaAllocator) PrintBrief(w io.Writer)
func (*ArenaAllocator) PrintUsed ¶
func (this *ArenaAllocator) PrintUsed(w io.Writer)
func (*ArenaAllocator) Stat ¶
func (this *ArenaAllocator) Stat() *ArenaAllocatorStat
func (*ArenaAllocator) String ¶
func (this *ArenaAllocator) String() string
func (*ArenaAllocator) Strlen ¶
func (this *ArenaAllocator) Strlen(addr MemPtr) int
func (*ArenaAllocator) Used ¶
func (this *ArenaAllocator) Used() uint32
func (*ArenaAllocator) ZeroMem ¶
func (this *ArenaAllocator) ZeroMem(addr MemPtr, num uint32)
type ArenaAllocatorStat ¶
type ArenaAllocatorStat struct {
// contains filtered or unexported fields
}
func (*ArenaAllocatorStat) AllocNum ¶
func (this *ArenaAllocatorStat) AllocNum() StatNumber
func (*ArenaAllocatorStat) AllocNumOk ¶
func (this *ArenaAllocatorStat) AllocNumOk() StatNumber
func (*ArenaAllocatorStat) ClearAllocNum ¶
func (this *ArenaAllocatorStat) ClearAllocNum()
func (*ArenaAllocatorStat) FreeAllNum ¶
func (this *ArenaAllocatorStat) FreeAllNum() StatNumber
func (*ArenaAllocatorStat) FreePartNum ¶
func (this *ArenaAllocatorStat) FreePartNum() StatNumber
func (*ArenaAllocatorStat) Init ¶
func (this *ArenaAllocatorStat) Init()
func (*ArenaAllocatorStat) Print ¶
func (this *ArenaAllocatorStat) Print(w io.Writer)
func (*ArenaAllocatorStat) String ¶
func (this *ArenaAllocatorStat) String() string
type MemPtr ¶
type MemPtr uint16
MemPtr save a integer value or a address shift of memory. * If highest bit is 1, it save a integer value, integer value range is between * 0 ~ 2**sizeof(MemPtr)-1
func MemPtrSetUint ¶
type StatNumber ¶
type StatNumber = uint64
Click to show internal directories.
Click to hide internal directories.