Certain performance-critical code, particularly in realtime/simulation/physics/game development, must ensure certain sections of their code do not allocate new memory. Example: Farseer PhysicsPhysics engines like Farseer Physics, written in pure C#, often take great pains to ensure that no new allocations happen during the performance critical phases of physics simulation (collision detection, integration, etc…). These sections of code must not allocate memory in order to ensure reliable realtime performance. Currently, the developers must use a profiler to check for allocations.
A [NoAllocate] annotation which, when applied to a function, turns on a constraint check that ensures no new allocations happen in any code-paths within the function. For example, in Farseer Physics, this attribute would be applied to the collision detection and integration step functions to ensure that they do not cause new allocations.
Static vs runtime constraint checking:
Static checking would be preferable, if feasible. Otherwise even a dynamic runtime check would be useful.
This would produce a false-positive for code that amortizes allocations dynamically. For instance, a particle system that dynamically grows its particle memory pools as the number of particles grows.