120 likes | 281 Views
Representing Data Elements. Representing Block and Record Addresses. By Ameya Sabnis CS 257 Section II. Pointer Swizzling. Generally pointers and addresses are the part of records Every block or record or object has two addresses
E N D
Representing Data Elements Representing Block and Record Addresses By Ameya Sabnis CS 257 Section II
Pointer Swizzling • Generally pointers and addresses are the part of records • Every block or record or object has two addresses • Database Address: When the data or object is in the secondary storage. These are of sequence of 8 bytes. • Memory Address: This is typically a virtual memory address. The address are typically of 4 bytes
Pointer Swizzling A translation table is needed to translate all the database addresses in the virtual memory to their current memory address. The translation table can be shown as: Database address Memory Address Translation Table
Pointer Swizzling • To avoid cost of translating from database address to memory address, several techniques are used collectively known as the Pointer Swizzling. • The general idea is when the block is moved from secondary to main memory the pointer is swizzed. • The pointer basically consists of a bit to show where the pointer currently is. • Consider the following example
Disk Memory Read into Memory Swizzled Block 1 Unswizzled Block 2
Types of Pointer Swizzling • Automatic Swizzling • Swizzling on demand • No Swizzling
Automatic Swizzling • In this as soon as the block is moved to memory all its pointers and addresses are entered into translation table. • The translation table is created straightforwardly, as we know where in the memory the block is moved. • When we enter the database address in the translation table, we may find it in table because its block is in memory. Thus we replace the database address by corresponding address and set swizzled bit true
Swizzling on Demand • Here all pointers are left unswizzled when the block is moved into memory. • We enter the address and the address of its pointer in the translation table along with its memory equivalent, only when we follow pointer P, inside the block memory. • Swizzling on demand tries to get all its pointers swizzled quickly and efficiently.
No Swizzling • No pointers are swizzled in this case. • The translation table is created so that pointers will be followed in their unswizzled form. • The only advantage with this is the records cannot be pinned in memory.
Returning Blocks to Disk • When a block is moved back from memory to disk all its pointers are unswizzled, also its memory addresses are replaced by database addresses. • Using the translation table it is possible to find out the database address corresponding to the memory address.
Pinned Records and Blocks • A block is said to be pinned if it cannot be moved back to disk safely. • A block is pinned when it is pointed by some swizzled pointer externally. • It is necessary to unswizzled all the pointers which points to the pinned block. • The translation table must record, for each database address whose data item is in memory the places in memory where the swizzled pointers to that item exist.