Is dynamic allocation of structures allowed?
显示 更早的评论
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!
回答(1 个)
Sean de Wolski
2013-11-19
0 个投票
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!
类别
在 帮助中心 和 File Exchange 中查找有关 Adaptive Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!