----- Ursprüngliche Nachricht -----
Von: Sergio Campamá
Gesendet am: 22 Aug 2011 13:36:07

> So the problem is not really malloc, but free… Interesting… I'll give that a 
> look. Thanks!

Actually, it's the way malloc/free works.
Putting a nail neatly into a tire doesn't give you a flat tire. But if you pull 
it out again...

Using only malloc does just waste a few bytes (at least two, depending on 
implementation)
for organizational issues.
In this case an plain incremental malloc that just keeps the address of the 
first unused byte
on the heap would be way more effective (and faster). But you could never free 
ram again.
However, malloc does offer freeing ram and has to keep the overhead, even if 
you don't use it.
Moreover, it needs to follow the chain of malloced areas to find the first free 
one. Which is
(relatively) slow.
And I doubt the MSP implementation has an algorithm to search for the best 
fitting hole,
using the first that is large enough. Which increases heap congestion for 
different-sized
mallocs.

However, a plain malloc version should be easy to implement yourself. Just 
start using
ram where the last variable ends, and keep a pointer to the first unused byte. 
(which is
the pointer to the first byte of the next allocated space)
No need to link malloc/free anymore, making your code smaller too.




On Aug 22, 2011, at 7:30 AM, JMGross wrote:

> ----- Ursprüngliche Nachricht -----
> Von: Sergio Campamá
> An: mspgcc-users@lists.sourceforge.net
> Gesendet am: 19 Aug 2011 17:53:45
> Betreff: Re: [Mspgcc-users] RAM Management
> 
>> Thanks for the insight into the problem. The thing is that I have a task
>> scheduler, a linked list that, well, lists the tasks to perform... Since
>> linked lists are dynamic in nature, I need malloc to create the new "task"
>> and append it to the list.. And after the task is done, I free the task and
>> go on to the next one...  The other place I use linked lists is to maintain
>> a list of timers that the application uses to signal certain events... after
>> the timer activates, it also gets freed...
> 
>> So that is why I need malloc and can't (or don't know how) to do it with
>> other types of dynamic storage, or static. (On that subject, what other
>> types of dynamic storage exist?)
> 
> You can use a semi-dynamic linked list.
> When a list element is freed, don't free it, just cut it from the list and
> append it to the end with a 'null task' entry.
> So when a new task comes up, the already allocated list element
> is found after the 'active' ones and can be reused. If the list is full,
> you can malloc another element and append it 
> (the list grows if necessary), but you never free it again.
> The list won't grow larger than required, bu twill not cause heap
> congestion.
> Also, it might be more performant (depending on your list 
> concatenation management, e.g. keep a pointer to the first free 
> element, etc.)
> 
> JMGross
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> uberSVN's rich system and user administration capabilities and model 
> configuration take the hassle out of deploying and managing Subversion and 
> the tools developers use with it. Learn more about uberSVN and get a free 
> download at:  http://p.sf.net/sfu/wandisco-dev2dev
> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users


------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to