[Go] mmm - manual memory management library.
Manual memory management for golang.
Have a look at FreeTree for a real-world example of how to use mmm.
mmmGo doesn't provide any manual memory management primitives. For very good reasons. This has been talked about numerous times on the go-nuts mailing list, have a look over there for detailed discussions.
To make it short: unless you are absolutely certain that you have no better alternative and that you understand all of the tradeoffs involved, please do not use this library.
mmm is no black magic: it simply allocates memory segments outside of the GC-managed heap and provides a simple API (Read(), Write(), Pointer()) that abstracts away all of the evil stuff actually going on behind the scenes.
The performances of Go's garbage collector depend heavily on the number of pointers your software is using.
No matter how much performance you gain by using mmm, you could have had the same gains had you redesigned your software to avoid the use of pointers entirely.
This is the raison d'être of mmm: in some cases, purposefully (re)designing your software to avoid the use of pointers actually leads to code that is overly complex, harder to reason about, and thus, harder to maintain. In such cases, mmm might allow you to completely eliminate the GC overhead issues in your software, while keeping your original design (with minimal changes to your implementation, of course).
Note that mmm heavily relies on Go's implementation of interfaces.
Finally, for the adventurous, you'll find most of the ugly stuff here and there.
UPDATE: this was discussed at length in this HN thread.
mmmIf the only references to your garbage-collectable data are stored in an unmanaged memory chunk, and thus non-existent to the eyes of the GC, your data will be automatically deallocated. As it should be.
mmm provides support for the following types: interfaces, arrays, structs, numerics/boolean (bool/int/uint/float/complex and their variants), unsafe.Pointer, and any possible combination of the above.Slices and string are thus not supported, use arrays and byte arrays instead.
mmm doesn't provide synchronization of reads and writes on a MemChunk.It's entirely up to you to decide how you want to manage thread-safety.
go get -u github.com/teh-cmc/mmmHere's a simple example of usage (code here):
…Complete code for the following demonstration is available here.
All of the results shown below were computed using a DELL XPS 15-9530 ([email protected]).
Let's see what happens when we store 10 millions pointers to integer on the managed heap:
// build 10 million pointers to integer on the managed heap
ints := make([]*int, 10*1e6)
// init our pointers
for i := range ints {
j := i
ints[i] = &j
}
for i := 0; iNo open issues yet, or sync has not completed.