简体   繁体   中英

Why is byte map faster than bit map?

I have read the The Garbage Collection Handbook. It says when doing card table,they use bytemap instead of bitmap, and said it is faster than bitmap, is it due to high speed cache line ? But as what i know ,the cache line normally is 64 bytes, if we make change on byte, race contention still exists , other cpu will still make the line invalidate ,it is the same as bit map ,anyone can help me on this ?

Not sure I got the context right but in general:

  1. bit map access

    requires address manipulation and read write of the whole BYTE/WORD/... as most architectures does not support bit read/write memory access.

    So for 8 bit bit map like:

     BYTE map[]; 

    the code for read it is:

     readed_bit=(map[bit>>3]>>(bit&7))&1; 

    set:

     map[bit>>3]|=1<<(bit&7); 

    clear:

     map[bit>>3]&=255^(1<<(bit&7)); 

    where bit is the bit you want to access. As you can see there is masking and bit shifts needed.

  2. BYTE map access

    this can be accessed directly on most architectures

     readed_byte=map[byte]; 

    set:

     map[byte]=1; 

    clear:

     map[byte]=0; 

    Where byte is BYTE you want to access. As you can see the memory space is wasted if just boolean value is stored in single BYTE.

So unless you got specific HW designed to work with bit maps and planes then BYTE maps are faster ... but to every rule there is an exception so there are algorithms where you already got the masked address and bit masks in such cases bit maps are faster or as fast as byte maps ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM