Allocation free delegate or other way to call method by address?

Viewed 3327

I need to be able to call a single method based on a function pointer in C# using Mono. Delegates work fine for this and it's their purpose, but they seem to allocate 52 bytes each time I set the delegate (not +=, but just setting it using = so there's always one and only one method referenced by the delegate).

This delegate changes many times per second and it causes the GC to kick in periodically which I'd like to avoid.

I don't mind the initial memory allocation, but is there a way to prevent an allocation each time I change the single delegate value?

If not, is there any other dynamic way to call a method in C# besides delegates that wouldn't allocate any memory each time the address is changed?

1 Answers
Related