about the heap:

Bert doclzs at 21cn.com
Wed Dec 10 04:44:48 UTC 2003


(1) what is the structure of the heap?

It said that what a heap looks like in memory immediately
after initialization is as follows:
 
             +--------------------------------+
      0      |  size = 0      | status = used |  a.k.a.  dummy back flag
             +--------------------------------+
      4      |  size = size-8 | status = free |  a.k.a.  front flag
             +--------------------------------+
      8      |  next     = PERM HEAP_TAIL     |
             +--------------------------------+
     12      |  previous = PERM HEAP_HEAD     |
             +--------------------------------+
             |                                |
             |      memory available          |
             |       for allocation           |
             |                                |
             +--------------------------------+
   size - 8  |  size = size-8 | status = free |  a.k.a.  back flag
             +--------------------------------+
   size - 4  |  size = 0      | status = used |  a.k.a.  dummy front flag
             +--------------------------------+

but i think it should be like:

             +--------------------------------+
      0      |  size = 0      | status = used |  a.k.a.  dummy back flag
             +--------------------------------+
      4      |  size = 8      | status = free |  a.k.a.  front flag
             +--------------------------------+
      8      |  next     = first              |
             +--------------------------------+
     12      |  previous = permanent_null     |
             +--------------------------------+
             |                                |
             |      memory available          |
             |       for allocation           |
             |                                |
             +--------------------------------+
             |  size = size-8 | status = free |  a.k.a.  back flag
             +--------------------------------+
             |  size = 8      | status = free |  a.k.a.  dummy front flag
             +--------------------------------+
             |  next     = permanent_null     |
             +--------------------------------+
             |  previous = last               |
             +--------------------------------+ 

right?

(2)
#define HEAP_OVERHEAD (sizeof( unsigned32 ) * 2)
#define HEAP_BLOCK_USED_OVERHEAD (sizeof( void * ) * 2)
#define HEAP_MINIMUM_SIZE (HEAP_OVERHEAD + sizeof (Heap_Block))

it said that "free block overhead is greater than used
 block overhead". Why?

(3)
typedef struct {
  Heap_Block *start;
  Heap_Block *final;
  Heap_Block *first;
  Heap_Block *permanent_null;
  Heap_Block *last;
  unsigned32  page_size;
  unsigned32  reserved;
}   Heap_Control;

Is "start" not the same as "first" and 
"final" not the same as "last"? if not,
what are the meanings of "start" and "final"?
and the relation between "first" "last" 
"start" "final"?


----------------------------------------------
ÍæÓÎÏ·Ó®ÊýÂëÏà»ú¡¢MP3¡¢UÅÌ 
http://mail.21cn.com/huodong/0310/ 
аÑÞ¾ªÈË ²¨°ÔÇǵ¤¡°°£¼°ÑÞºó¡±Ð´Õæ(ͼ) 
http://news.21cn.com/huahua/ 
¹ã¶«ADSLÓû§ÓÐ×ÅÊý£¬21CNÉÌÎñÓÊÃâ·ÑÁì 
http://mail.21cn.com/huodong/0310/ 
ÃÀ¹úÂôÒùÊÀ¼Ò½ÒÃØ:Å®¶ù¼ËŮĸÀÏð±(ͼ) 
http://news.21cn.com/social/ 






More information about the users mailing list