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.

~ by Azeem on July 23, 2008.

One Response to “Optimizing IO Via Buffer”

  1. [...] This cup of tea was served by: Azeem Personal play ground [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: