Is dynamic allocation of structures allowed?
Afficher commentaires plus anciens
I am writing a particle simulator, each particle has the following structure:
myFriend.name % string of unknown length (until loaded)
myFriend.number % int
myFriend.position % 1x3 vector double
myFriend.hisFriend % array of structures of type myFriend, length variable
During the simulation the number of myFriend structures varies, as well as the number of hisFriend structures for each myFriend structure that is present at that time.
Is it kosher to allocate these "on the fly"? How does one deallocate them? Is deallocation necessary to prevent memory leaks? Sorry for the elementary nature of these questions. TIA!
Réponses (1)
Sean de Wolski
le 19 Nov 2013
0 votes
Can you allocate on the fly:
- Yes. Use dynamic fieldnames to create additional fields as necessary
Do I need to worry about memory leaks and cleanup?
- No. MATLAB takes care of this for you!
Catégories
En savoir plus sur Adaptive Control dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!