memory

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package memory offers gogen templates for memory managemant, structs can help to compose structure that takes garbage collection into account it gets rid of pointers, or lowers the allocations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capsule

type Capsule struct {
	// contains filtered or unexported fields
}

Capsule is something like an optional type, it holds boolean about whether it contains value though it does not hold pointer

type QuickPool

type QuickPool struct {
	// contains filtered or unexported fields
}

QuickPool ... def( rules QuickPool<T> QuickPool is template that can store interface referenced objects on one place reducing allocation, if you are creating lot of date stored behind interface that has very short livetime QuickPool can be nice optimization

func (*QuickPool) Item

func (q *QuickPool) Item() *T

Item returns pointer to pooling struct that is free, if no free struct is present new one is allocated

func (*QuickPool) Over

func (q *QuickPool) Over(val T) *T

Over overwrites by raw value and returns pointer to its new position

func (*QuickPool) Restart

func (q *QuickPool) Restart()

Restart makes QuickPool reuse old objects, if you cannot call this as pooling structs you taken are constantly referenced, its useles to use QuickPool in first place

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage ... def( rules Storage<T, int32> dep Capsule<T, Capsule> Storage generates IDs witch makes no need to use hashing, only drawback is that you cannot choose the id, it will be assigned like a pointer, but without putting presure no gc, brilliant storage for components. Its highly unlikely you will run out of ids as they are reused

func (*Storage) Allocate

func (s *Storage) Allocate() (*T, int32)

Allocate allocates an value and returns id and pointer to it. Note that allocate does not always allocate at all and just reuses freed space, returned pointer also does not point to zero value and you have to overwrite all properties to get expected behavior

func (*Storage) Clear

func (s *Storage) Clear()

Clear clears storage, but keeps allocated space

func (*Storage) Count

func (s *Storage) Count() int

Count returns amount of values stored

func (*Storage) Item

func (s *Storage) Item(id int32) *T

Item returns pointer to value under the "id", accessing random id can result in random value that can be considered unoccupied

method panics if id is not occupied

func (*Storage) Len

func (s *Storage) Len() int

Len returns size of storage

func (*Storage) Occupied

func (s *Storage) Occupied() []int32

Occupied return all occupied ids in storage, this method panics if Storage is outdated See Update method.

func (*Storage) Remove

func (s *Storage) Remove(id int32)

Remove removes a value and frees memory for something else

panic if there is nothing to free

func (*Storage) SlowClear

func (s *Storage) SlowClear()

SlowClear clears the the Storage slowly with is tradeoff for having faster allocating speed

func (*Storage) Used

func (s *Storage) Used(id int32) bool

Used returns whether id is used

type T

type T struct{}

T is template parameter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL