Skip to content

Object ownership, refcounting and memory allocations #1475

Answered by jrouwe
godlikepanos asked this question in Q&A
Discussion options

You must be logged in to vote

Why Body is not refcounted? Are there more special objects like that?

Body is not refcounted because it requires very careful memory management: it is the main class that is safe to access from multiple threads. Also, internally Body and its (SoftBody)MotionProperties are allocated in the same memory block so you can't just call delete on them. This is done for performance reasons. I think it's the only object that is special in that way.

For shapes and constraints I can allocate the memory myself by bypassing Jolt's new/delete. I can just use my own memory, call placement new and finally call SetEmbeded(). Body is special once again when it comes to allocation. Why can't I allocate it…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@MasterDrake
Comment options

@jrouwe
Comment options

@MasterDrake
Comment options

Answer selected by godlikepanos
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants