Pagehandle page returncode code file getfirstpagepage

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ing excep6onal condi6ons •  Use tools like valgrind to track down memory leaks •  We will check for memory leaks when grading your projects Memory Management for Shared Objects •  When several parts of the code are using same object, how do we know when object is “no longer being used”? –  so that it can be freed (C++ object), or evicted from buffer pool (page), or ... •  Standard solu6on in C/C++: use reference coun:ng –  When code needs an object, increment the reference count –  When finished, decrement the reference count –  Pisalls? •  For example, Microsoj COM/OLE objects have methods addRef and release to do this •  In DBMS buffer pool, tradi6onal names for the methods are pin and unpin Coding Tip: Pinning/Unpinning Pages •  Whenever you access a page, you must remember to unpin it ajer you're done (else you leak the page) •  Best coding prac:ce: do both tasks nearby, ideally in the same func6on, so that correctness can easily be verified PageFileHandle* file;! PageHandle page;! ! ReturnCode code = file->getFirstPage(&page);! if (code == RC_OK) {! !// … do stuff with page …! !file->unpinPage(page.pageNo);! }! •  Same goes for memory alloca6on/de ­alloca6on –  make it easy to match every new with its corresponding delete Coding Tip: Don't Forget to Mark Pages Dirty! •  Be diligent about getng this right from the beginning, else you risk introducing tough ­to ­track ­down bugs FileHandle* file;! PageHandle page;! ! ReturnCode code = file->getFirstPage(&page);! if (code == RC_OK) {! !// … modify contents of page …! !file->markDirty(page.pageNo);! !file->unpinPage(page.pageNo);! }! Coding Tip: Asser6ons in Page File Manager •  Page file manager makes heavy use of run6me asser6ons; some of these will catch your bugs! ReturnCode PageFileManager::allocateBlock (PageFileHandle* fileHandle, int pageNo, char** data) {! !// first, loo...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online