RandyGaul / qu3e

Lightweight and Simple 3D Open Source Physics Engine in C++
zlib License
920 stars 110 forks source link

Switched to dynamic memory for q3Stack. #26

Closed isegal closed 7 years ago

isegal commented 7 years ago

I had a use-case where the number of bodies could be anywhere from a few to over a thousand and was not very predictable. At default I was running out of q3Stack space. Didn't want to increase stack size and waste memory, so ended up switching to using dynamic memory and a Reserve() function. I was also thinking of making it shrink when Reserved request is <10% capacity or something along those lines.

Scenario: Suppose you have a game with the world which is stream-loading and the areas fluctuate in terms of number of bodies, it would be good to have the memory allocated and released based on demand.

RandyGaul commented 7 years ago

Like the other pull request, seems like a good idea and I'll check it out soon. Thanks for contributing! My initial reaction is to just expose a Compact function to the user. Whenever called will compact the stack if possible. This allows the user to have specific control over memory usage. Perhaps adding in some gettors will help users decide what metric to use for deciding when to call Compact.

Automating the compacting (like at 10%) could work, but generally users will just want custom control anyway, and can easily implement their own 10% predicate.