简体   繁体   English

为什么字节映射比位图更快?

[英]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 ? 但正如我所知,缓存行通常是64字节,如果我们对字节进行更改,竞争争用仍然存在,其他cpu仍会使该行无效,它与位图相同,任何人都可以帮助我吗?

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. 需要地址操作和读写整个BYTE / WORD / ...因为大多数架构不支持位读/写内存访问。

    So for 8 bit bit map like: 所以对于8位位图来说:

     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. bit是您要访问的位。 As you can see there is masking and bit shifts needed. 如您所见,需要进行掩蔽和位移。

  2. BYTE map access BYTE地图访问

    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. 其中byte是您要访问的BYTE。 As you can see the memory space is wasted if just boolean value is stored in single BYTE. 正如您所看到的,如果只是布尔值存储在单个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 ... 因此,除非你得到专门用于处理位图和平面的硬件 ,否则BYTE贴图会更快...但是对于每个规则都有一个例外,因此有些算法你已经获得了掩码地址和位掩码,在这种情况下位图是比字节映射更快或更快......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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