View Single Post
  #1   Spotlight this post!  
Unread 11-02-2008, 21:35
CrazyNorman CrazyNorman is offline
Registered User
FRC #1100
 
Join Date: Feb 2008
Location: Northborough, MA
Posts: 2
CrazyNorman is an unknown quantity at this point
Re: Want Malloc on FIRST?

Sorry, I exaggerated when I said that dynamic allocation would be 100% necessary, as dynamic allocation can be written in terms of static allocation (as here). On the other hand, having a dynamic allocation system for certain things can result in cleaner code than without.

For example, lets say that in your autonomous, you want to watch out for nearby obstacles such as robots. When the rangefinder picks them up, you could store their location relative, a time, etc. Then, as objects are no longer detected for a certain amount of time, pass out of range, etc., you delete them. Now, you could have a stack, find the first unused "object", store in it, loop through them, make sure they are within range, mark them as unused, etc.

Of course, now you just wrote a local dynamic allocator for that section of code, and when another part of your code works upon semi-similar principles, you just have to rewrite it again. Yet another chance for duplication, mistakes, and horrors.

On the other hand, you could have a generic allocator which works consistently, and use it everywhere that it results in cleaner code than the custom written stack. Don't use this everywhere, but I'm sorry, static variables everywhere and custom stacks don't necessarily result in more bug- free code.