c - Reading memory in correct order Need some help -



c - Reading memory in correct order Need some help -

we storing sort of records in memory location follows

---------------------------------------------- |eventid | timestamp | variable info | length | ----------------------------------------------

lengths of these fields follows

eventid+ timestamp 12 bytes length fields 4 bytes , indicates length of info field.

millions of such records placed 1 after other & have pointer pointing current index, if want read records go read 4 bytes right left & fetch particular record & doing iteratively read finish memory space. problem method reads records in reverse order compared order in entered.

i need device method allow me read memory records in same order entered minimal space complexity.

as variable length info section comes before length, impossible read info starting origin memory address. assuming no changes can made architecture or storage, 1 possible alternative utilize current scheme build index of variable info lenghts. then, 1 time reach origin of info read records in right order - using previous built index determine variable info length.

however, mention dataset contains millions of records. storing index of variable info lengths before processing may not feasible. 1 such solution problem index every other entry, or every fourth, eight, etc... depending upon specific requirements. start @ each indexed record, work backwards temporarily saving info lengths until reach record havn't processed. work forwards 1 time again using saved data.

for example, let's index every 8 records first pass. then, start @ record 8 , save length of record. go 7, 6, 5, 4, 3, 2, 1. you've saved next 8 lenghts. process record 1, 2, 3, 4, 5, 6, 7, , 8. now, don't know length of 9 - jump 16. record 16, 15, 14, .., 9 lengths. 1 time again before process 9, 10, 11 ... 16. repeat.

c algorithm

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -