What is the operator for in the context of virtual memory paging?

0

I'm seeing the virtual memory implementation and I have this code:

#define INDEX_FROM_BIT(a) (a / 8*4)
#define OFFSET_FROM_BIT(a)(a % (8*4))



static void set_frame(u32int frame_addr)
{

    u32int frame = frame_addr/0x1000;

    u32int idx = INDEX_FROM_BIT(frame);

    u32int off = OFFSET_FROM_BIT(frame);

    frames[idx] |=(0x1 << off);
}

static void clear_frame(u32int frame_addr)
{
    u32int frame = frame_addr/0x1000;

    u32int idx = INDEX_FROM_BIT(frame);

    u32int off = OFFSET_FROM_BIT(frame);

    frames[idx] &= ~(0x1 << off);

}

Why is this (0x01 << off) so used as its context for virtual memory?

    
asked by anonymous 15.12.2015 / 22:35

1 answer

4

This is the bit-shift operator . It is faster to do exponentiation when the base is 2.

The use in virtual memory is broad, it depends on each context.

Obviously access to physical memory is always done through calculations in relation to the original virtual address. You also need to make markings of where each page is. In short, it depends on the implementation but the field of computation as a whole benefits from operations of direct manipulations of bits because our area works naturally with numbers and sets based on 2.     

15.12.2015 / 22:43