开发者

Emulating a Paged File System in C++ using fstream objects

开发者 https://www.devze.com 2023-01-20 13:35 出处:网络
I need to emulate a paged file system in C++. Need to store multiple tuples in a page(block of a file) with a directory at the end of each page pointing to the offset of each tuple on the page. I also

I need to emulate a paged file system in C++. Need to store multiple tuples in a page(block of a file) with a directory at the end of each page pointing to the offset of each tuple on the page. I also need to store variable length attributes in the tuples. Would using an STL container and serializing it to disk be the best way forward?

Thanks

A few more details about what I'开发者_运维技巧m looking for- I have created a file - say employee.day with blocks of 4096bytes. I need to store tuples in each block with a directory at the end of each block that stores the address and offset of each tuple. Each time I insert a new tuple I need to find a page with enough free space and insert it into the page and update the directory at the end of the page. My tuples can be of variable length, so I also need to store the length of the tuples in the file. I have the schema of the table loaded into a vector during the operation of the program. I'm looking for some ideas on how to implement the storing of tuples into the page using just the read and write operations in fstream,


Without any more details, I'd say to make a vector for the page, seekp/seekg to the right position, and serialize/deserialize the page with

file << v.size();
file.write( &v[0], v.size() * sizeof( my_tuple ) );

file >> page_size;
v.resize( page_size );
file.read( &v[0], v.size() * sizeof( my_tuple ) );
0

精彩评论

暂无评论...
验证码 换一张
取 消