TAILIEUCHUNG - C++ Timesaving Techniques for Dummies phần 7

Tham khảo tài liệu 'c++ timesaving techniques for dummies phần 7', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Technique 48 Implementing Virtual Files Listing 48-1 continued void setOffset long offset _offset _offset void setLength long length _length length void setChunk const string chunk _chunk chunk long AccessCount void return _accesses bool Load ifstream in long offset long length Clear return Read in offset length const int kChunkSize 128 class FileChunkManager - 2 private int _numChunks FileChunk _chunks ifstream _in string _fileName protected FileChunk findChunk long theOffset for int i 0 i _numChunks i if _chunks i .InUse true long offset _chunks i .Offset long length _chunks i .Length if theOffset offset theOffset offset length return _chunks i return NULL FileChunk addChunk long theOffset Creating a Virtual File Class 287 for int i 0 i _numChunks i if _chunks i .InUse false if _chunks i .Load _in theOffset kChunkSize return _chunks i return NULL FileChunk getLeastRecentlyAccessed int idx 0 long access _chunks 0 .AccessCount for int i 0 i _numChunks i if _chunks i .InUse true if _chunks i .AccessCount access idx i access _chunks i .AccessCount return _chunks idx public FileChunkManager void _numChunks 0 _chunks NULL FileChunkManager const char fileName int nMaxChunks _numChunks nMaxChunks _chunks new FileChunk nMaxChunks _fileName fileName fileName FileChunkManager const FileChunkManager aCopy _numChunks _chunks new FileChunk _numChunks for int i 0 i _numChunks i _chunks i i _fileName continued Technique 48 Implementing Virtual Files Listing 48-1 continued virtual FileChunkManager void delete _chunks char operator long offset Find which chunk this offset is in. FileChunk chunk findChunk offset if chunk NULL There are none. See whether we can add one. chunk addChunk offset If we have one just get the data from it. Otherwise we have to go dump one. if chunk chunk getLeastRecentlyAccessed chunk- Load _in offset kChunkSize Finally extract the piece we need. int pos offset - chunk- Offset

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.