Is dynamic allocation of structures allowed?
Mostrar comentarios más antiguos
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!
Respuestas (1)
Sean de Wolski
el 19 de Nov. de 2013
0 votos
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!
Categorías
Más información sobre Adaptive Control en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!