I see that for example the function GetNarrowPhasePair generate garbage too
That method should not generate garbage. It will, however, allocate if no object is available in the pool. The engine must scale up its resources to handle larger simulations with more collisions. Those allocations are either in use or in a pool, so they're not garbage.
Note that allocations alone are not a significant issue. Allocating a bunch of data does not directly result in garbage collections of that same data later (although it may trigger garbage collections of
other now-unused data or compactions to make room); it must first go out of use.
A secondary consideration is that a more complex heap can make GC take a bit longer, but it's usually better to just avoid causing a GC under normal circumstances. Making the heap simple enough that a GC runs smoothly without dropping a single frame ever can be very tricky (or impossible), especially on the Xbox360.
and use Activator Create Instance...(10x more slow that new..:p)
In the engine itself somewhere? The narrow phase factories and pools use generic new constraints, not Activator.CreateInstance. There's a few Activator uses in the BEPUphysicsDrawer, but they're irrelevant compared to the rest of the costs involved.
[Edit/Note: It actually looks like the CLR v4 generic new constraint is still using a form of Activator.CreateInstance internally. I might eventually do something fancier, like emitting and caching a function to construct the type, but it's not generally a bottleneck anyway.]
So maybe there is a way at the beginning to define Pool Size?
Yes, every pool can be given an initial resource count. The narrow phase pair factories are the easiest to reach and initialize in the NarrowPhaseHelper.
There's reasons why setting the initial sizes can be useful:
-The simulation is expected to expand extremely rapidly. Creation of objects is fast, but if there's a giant tower of blocks destined to fall into a pile with 50,000 collision pairs, the factory might as well be primed to move the object creation cost to load time.
-While the GetNarrowPhasePair method and other pool-requesting methods do not create garbage, returning objects to their pools once the simulation quiets down can force internal list resizes in the pools. This form of garbage is usually quite rare and inconsequential. However, careful initialization of the resource pools can avoid it if really needed.