SkillAgentSearch skills...

GCFreeClosure

A gc-free closure implementation for unity

Install / Use

/learn @lujian101/GCFreeClosure
About this skill

Quality Score

0/100

Supported Platforms

Universal

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:

//-----------------------------------------------------------------------------------
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<int>();

// 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<int>();

//-----------------------------------------------------------------------------------
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 );
View on GitHub
GitHub Stars89
CategoryDevelopment
Updated4mo ago
Forks11

Languages

C#

Security Score

77/100

Audited on Nov 27, 2025

No findings