C++ data block management -
(having trouble coming question title here!)
in last few months, seem keep writing code doing same task (in minor variations). i'm wondering if there's in c++ standard libraries (or maybe boost) can help. let me try explain i'm trying do…
as concrete example, suppose have logical file that's made of several physical files on disk. want write function like
void readdata(void * buffer, uint64 offset, uint64 size);
seems simple enough, right? however, it's quite fiddly:
- first, need figure out physical file contains requested logical offset.
- next, need check whether requested
size
spans physical file boundary. - actually, in worst case, it's plausible
size
span multiple files, although that's unlikely. - finally, need
fread()
right blocks of data, right files, right offsets inbuffer
. - checking neither
offset
norsize
exceeds available data prudent well.
none of astonishingly hard, it's fiddly , easy screw up. there endless opportunities off-by-one bugs, out-of-bounds accesses , forth. it's awkward test thoroughly. in short, isn't sort of code want end writing multiple times over.
does know of in libraries me here? i'm interested in handling coordinate transformations, not actual i/o operations themselves.
Comments
Post a Comment