Thread: Malloc, etc...
View Single Post
  Spotlight this post!  
Unread 05-01-2004, 02:01
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Malloc, etc...

Quote:
Originally Posted by rwaliany
Oh yeah, I couldn't find malloc or calloc, it's driving me crazy, C WITH NO MALLOC AAAAAAAAAAAAH!
Ryan,

Just to amplify what Jim said, malloc() is really, really evil for small, embedded systems. It's a better practice to allocate all memory at run time (the stack is a special case) so that you are guaranteed to live (execute) within your means. For many reasons (e.g., fragmentation), memory managment without a real hardware memory managment unit (MMU) is a really tough problem. The size of the stack can be tweaked by initializing the stack to a fixed value (not zero) at runtime (see _startup() in ifi_startup.c), exercising all aspects of your code, and then examining the stack space to see where the "high water mark" is located. If you see that you came really close to using all of the stack space, you can allocate more at run time. Conversely, if you have a bunch of unused stack, you can free up some of that memory for other uses.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org