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!

Answers (1)

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!

Categories

Asked:

on 19 Nov 2013

Answered:

on 19 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!