Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/lujian101/GCFreeClosure

A gc-free closure implementation for unity
https://github.com/lujian101/GCFreeClosure

Last synced: 4 months ago
JSON representation

A gc-free closure implementation for unity

Lists

README

        

# GCFreeClosure
A gc-free closure implementation for unity

GC-Alloc has always been a kind of important performance measurement standard, so we should keep gc-alloc as less as possible.
GCFreeClosure is designed for avoiding gc memory allocation.

example:

```C#
//-----------------------------------------------------------------------------------
var action = ActionClosure.Create( ( a, b ) => UDebug.Print( a + b ), 1, 2 );
action.Invoke();

var function = FuncClosure.Create( ( a, b ) => a + b, 1, 2 );
var c = function.Invoke();

// use Tuple to pack multi-value together
var function2 = FuncClosure.Create( ctx => ctx.Item1 + ctx.Item2, STuple.Create( 1, 2 ) );
// call with return value
var c2 = function2.Invoke();

//-----------------------------------------------------------------------------------
var id = 1;
// system library implementation will cause gc-alloc for each function call.
list.FindIndex( e => e == id );

// replace system implementation to avoid gc-alloc
list.FindIndex( ( _id, e ) => e == _id, id );
```