Comments (7)
Good point. I'll consider the options.
from bulletsharp.
Wow, didn't expect such quick response! :) Currently I'm working on cache implementation in my client code. The only problem I have is to detect when new manifolds are added internally by Dispatcher. Once I have it figured out I'll post my solution - may be it'll help you.
Keep up the good work!
from bulletsharp.
Yeah, manifolds are hard to track since there are so many generated and handling them is performance-critical. Detecting when new manifolds are created is hard and it's also hard to detect when they are removed, which is again important for keeping garbage down.
I'm not sure if making PersistentManifold a struct helps, because they will be boxed into objects (e.g. when returned from GetManifoldByIndexInternal), so they'll still need to be garbage-collected.
This hasn't been a big priority so far, so I haven't thought about it very much. If you can figure it out, then that would be great. Thanks!
from bulletsharp.
Here's a patch that turns PersistentManifold into a value struct. Can you test it?
http://pastebin.com/5d72sLqS
The public PersistentManifold constructors are removed, but this is OK, because manifolds should only be created in Dispatcher::GetNewManifold anyway.
Also, since structs can't be inherited, PersistentManifold no longer inherits from TypedObject, but that probably isn't strictly necessary for anything.
After 7 years of .NET development, the GC is still confusing as hell :). But if I had to guess, there's less garbage generated with this patch since without the finalizer, the manifolds can be collected in GC generation 0 (if the PersistenManifolds should get boxed into objects).
from bulletsharp.
Ok, I'll test it once I have some time for it. I have forked your repository so you can push your fix in to it:
https://github.com/Zolniu/BulletSharp
In the meantime I've found quite good workaround for this problem. I use gContactProcessedCallback callback to store information about collisions and then I can work with them in my code. It produces a lot less garbage - I can have custom logic for over 800 colliding objects and I'm getting one garbage collection every few minuts. I had to modyfi PersistentManifold::onContactProcessed method to only fire if processed CollisionObject has CustomMaterialCallback flag. You can check it here:
https://github.com/Zolniu/BulletSharp/blob/master/src/PersistentManifold.cpp
About GC, it can be tricky indeed. Not only boxing can lead to "hidden" allocations, foreach over IEnumbrable also allocates memory, but only if used via IEnumerable interface. For example List provides explicit GetEnumerator() method which returns enumerator structure so foreach over List does't generate garbage, but if you change your reference to be IList (interface) it will generate garbage since foreach will use GetEnumerator() via IEnumerable interface inherited by IList interface.
from bulletsharp.
I've made some test in my with my current setup and it is quite obvious that after changing Persistent Manifold to struct you can iterate through all the manifolds without such massive amounts of memory allocations as before. I think we can close this issue.
BTW. I also suggest to change all the IList references to List. As I mentioned above, using foreach operator over IList generates garbage. I know that we should depend on interfaces wherever possible but I think that this is one place, where exception is justified.
from bulletsharp.
Ok, cool. Thanks!
I'll do some research on the IList enumeration.
from bulletsharp.
Related Issues (20)
- how to compile dll from src? HOT 1
- Hi Vb.net developer issue when I try to remove ridgid body!!! HOT 3
- Stop simulate HOT 9
- Why does BasicDemo have many errors??? HOT 2
- Bullet Physics Version Update HOT 4
- Problem with BulletSharp with Debug x64 and Release x64 HOT 2
- MultiThreadedDemo, A heap has been corrupted exception HOT 3
- Build instructions for non C++ developers HOT 2
- Link is broken for downloading x64 release HOT 1
- AccessViolationException while BulletSharp.DynamicsWorld.StepSimulation HOT 2
- Example without Demo UI
- .NET Core compatibility HOT 6
- Strange behaviour HOT 4
- UnhandledException : Removing object that is not being tracked. at Finalize() HOT 2
- btTransform wrapper HOT 4
- How can BulletSharp.dll be built as AnyCPU .dll HOT 1
- BulletSharp, OpenTK & Scale HOT 4
- Unhandled Exception on ~btGImpactMeshShape()
- C# Demo Build Issues - Consistent Versions of Dependencies? HOT 1
- Passing Through object
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bulletsharp.