Optimizing IO Via Buffer
Times come when you have to write some logger or a file opertions that does I/O and that code of yours get used on huge web applications that serves 1000′s of web request doing I/O Back and forth could be a pain in arse.! So an alternative approach would be to make a buffer and when ever that buffer reaches a particular limit do an I/O either one can do explicit checking of buffer that is being maintained however there are other way around one way i thought of is to make a private variable and setting up there getter and setter where in setter a buffer gets checked and IO is performed
for eg.
private int _buffer ;
public int Buffer {
get {
return _buffer;
}
set {
_buffer = value;
CheckBuffer();
}
}
Now When ever you do
Buffer += somevalue ;
CheckBuffer() is called and it will contain a logic to reset _buffer and do I/O
However what if buffer never gets filled to max buffer size there would be no I/O and data would get lost. so for that a function to commitwrite() should be written that would do I/O upon and should be called in Destructor of the class so that whenever the objects is getting destructed anything in buffer should be write back to file or any IO.




[...] This cup of tea was served by: Azeem Personal play ground [...]
Optimizing IO Via Buffer | Tea Break said this on July 26, 2008 at 11:40 am |