Skip to content

csorchard/malloc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Malloc

Go Reference

This is a proof-of-concept memory allocator for Go. A fixed-size chunk of memory is held by the arena and handed out as needed, similar to malloc(3).

Basic usage:

arena := malloc.NewArena(1024)
pointer := malloc.Malloc[SomeStruct](a)
defer malloc.Free(pointer)

// pointer is now a *SomeStruct allocated inside the arena.

For a more complete example see example/stack.go.

It uses a fairly primitive first-fit algorithm to allocate memory. This is simple to implement for a proof of concept, but it has some drawbacks:

  • The smallest size that can be allocated is 16 bytes.
  • Sizes which aren't divisible by 16 will be rounded up.
  • It probably fragments easily.

Credits

The algorithm is taken from Donald Knuth's first-fit memory allocator in The Art of Computer Programming Vol. 1.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%