[En-Nut-Discussion] question about heap.c

Ernst Stippl ernst at stippl.org
Tue Mar 18 07:35:45 CET 2008


Hi Nathan!

Well, deadbeef is a marker and the next heap pointer is built "behind"(!)
it.
Have a look: (>< lines are the comments I added) 

CLI>
26204 Bytes free on Heap                 
><- current free heap memory
CLI>
26204 Bytes free on Heap
CLI>dump r,18a3                                                         
><- start of heap free list = addr of 1st HEAPNODE  = 18a3
18A3 5C 66 00 00 20 42 79 74 65 73 20 66 72 65 65 20 *\f.. Bytes free * 
><- 665c = 26204 free heap size (OK)
18B3 ^^^^^^^^^^^ 65 61 70 0D 0A 00 EF BE AD DE 3E 66 *on Heap.......>f*
18C3 00 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
18D3 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
18E3 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
18F3 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1903 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1913 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1923 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1933 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1943 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1953 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1963 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1973 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1983 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1993 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*

CLI>halloc 0080
Alloc 0x80 Bytes               
><- allocate 0x80 bytes from heap (new free= 26204 - 0x80 - 6 = 26070 = 65D6
Allocation Ptr = 18a5        
><- allocation ptr = (old HEAPNODE addr) + 2 (the 2 bytes below contain
memory chunk size)
CLI>dump r,18a3
18A3 86 00 00 00 20 42 79 74 65 73 20 66 72 65 65 20 *.... Bytes free * 
><- 86 00 is memory chunk size
18B3 ^^^^^ 20 48 65 61 70 0D 0A 00 EF BE AD DE 3E 66 *on Heap.......>f*
18C3 00 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
18D3 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
18E3 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
18F3 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1903 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1913 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1923 FF 00 EF BE AD DE D6 65 00 00 FF 00 FF 00 FF 00 *.......e........*
><- end of alloc'ed memory at 1924 plus deadbeef marker plus new HEAPNODE
1933 FF 00 FF 00 FF 00 ^^^^^^^^^^^ FF 00 FF 00 FF 00 *................* - 
1943 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1953 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1963 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1973 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1983 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
1993 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 *................*
CLI>
26070 Bytes free on Heap
CLI>lists

--Heapnode, len=4, ptr=0xAA2
1929 D6 65 00 00                                     *.e..*
>< points "behind" deadbeef marker to new HEAPNODE
CLI>

Regards

Ernst

-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von Nathan Moore
Gesendet: Montag, 17. März 2008 16:17
An: en-nut-discussion at egnite.de
Betreff: [En-Nut-Discussion] question about heap.c

I was looking over the heap.c code and ran across MEMOVHD and
something jumped out at me.

>From line 141:
#define MEMOVHD (sizeof(size_t) + sizeof(0xDEADBEEF))

As I understand it this is supposed to account for the size of the
memory chunk and the size of
the pointer to the next pointer -- ie, sizeof(struct HEAPNODE).

What stood out to me about this was that on AVR sizeof(0xDEADBEEF) is
twice as big as
sizeof(void *).  Is the overhead really too big on AVR or am I
misunderstanding something?

Nathan
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion



-- 
No virus found in this incoming message.
Checked by AVG. 
Version: 7.5.519 / Virus Database: 269.21.7/1332 - Release Date: 17.03.2008
10:48





More information about the En-Nut-Discussion mailing list