View Single Post
  #2   Spotlight this post!  
Unread 12-02-2008, 11:49
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,815
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Want Malloc on FIRST?

Quote:
Originally Posted by CrazyNorman View Post
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.
And yet a simpler way of doing that might be to create an array at runtime that represents the space around you, and when you detect something store a loop counter (representing time) in the corresponding space in the array. You automatically overwrite older locations, which isn't a problem, and you only 0 something out when you actually care about whats in that space (because you're moving there, lets say)... There are some extremely efficient algorithms you can use to move the array and rotate it and such as your robot moves (trust me, i've used them all before for graphics processing).

In the end, there are other ways to do it that are just as simple (or simpler) and just as elegant, but don't carry the negatives of attempting to use dynamically allocated memory in a situation where you have extremely limited resources.