patchAVR C Runtime Library - Patches: patch #6555, malloc improvement

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #6555: malloc improvement

Submitter:  Gerben van den Broeke <gerben>
Submitted:  Sat 28 Jun 2008 02:05:50 PM UTC
   
 
Category:  None Priority:  3 - Low
Status:  Done Privacy:  Public
Assigned to:  joerg_wunsch Open/Closed:  Closed

Tue 08 Jun 2010 12:19:01 PM UTC, comment #2: 

Patch applied, thanks!

Joerg Wunsch <joerg_wunsch>
Group administrator
Tue 19 Aug 2008 08:42:04 PM UTC, comment #1: 

So far the patch looks good to me.

Joerg, can you take a look at this patch?

Eric Weddington <arcanum>
Group administrator
Sat 28 Jun 2008 02:05:50 PM UTC, original submission:  

Current implementation:
malloc loops trough all the holes in the freelist, checking if there is a hole with exactly the right size (len), in which case it takes the hole and returns it.
While looping it also notes down the size of the smallest hole it has found that is still big enough (size > len).
If it cannot find a hole with exactly the right size, it will use this noted hole.
But because it only noted the size of the hole, it loops through all the holes again until it has found a hole with that size, then uses that hole.

Improvement:
By not only noting down the size of the smallest hole, but also noting its addrress, the second loop is not necessary anymore.

The cost:
2 more pointers are needed (both the found hole and the hole before it must be remembered), so it might add 4 pushes at the beginning and 4 pops at the end of the function.
In the first loop two movw's are needed to note down the hole address, which are executed everytime a smaller hole is found.

The gain:
The whole second loop can be removed, which saves much program space (whole malloc becomes about 10% smaller) and even more execution time.

Note: using -Wall gcc produces a warning:
  avr-libc-1.6.2/libc/stdlib/malloc.new.c: In function 'malloc':
  avr-libc-1.6.2/libc/stdlib/malloc.new.c:68: warning: 'sfp2' may be used uninitialized in this function
  avr-libc-1.6.2/libc/stdlib/malloc.new.c:68: warning: 'sfp1' may be used uninitialized in this function
If gcc would have been smarter it would see that they are not used uninitialized.

Gerben van den Broeke <gerben>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #15951:  malloc.diff added by gerben (3KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by joerg_wunsch (Posted a comment)
  • -email is unavailable- added by arcanum (Posted a comment)
  • -email is unavailable- added by gerben (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-06-08 joerg_wunsch StatusNone Done
        Open/ClosedOpen Closed
    2008-08-19 arcanum Assigned toNone joerg_wunsch
    2008-06-28 gerben Attached File- Added malloc.diff, #15951

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code