Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Efficient 'logging' mechanism?

Reply
Thread Tools

Efficient 'logging' mechanism?

 
 
idesilva@eudoramail.com
Guest
Posts: n/a
 
      12-09-2004
Hi,

I have an application which sends/receives messages at a very high
rate. This app needs to 'log' the contents of these messages. Since the
msg rate is high, 'logging' each and every msg to a disk-file reduces
the app's performace significantly. I want to device a 'logging'
mechanism where the 'log' is actually buffered and it will be written
to the disk periodically. The time of writing to disk should be
controlled by the app rather than by the OS. At times, I also want to
reset the in-memory log without writing to disk.

Currently I use an 'ofstream' object for this purpose. But it does not
allow me to *control* buffering. I tried out another option as follows.

I extended the MFC's CMemFile class.

class CMemLogFile : public CMemFile
{
public:
CMemLogFile(CString sName);
virtual ~CMemLogFile();

// Base class overrides
void Close();

void Truncate();
void WriteToDisk();

private:
CFile m_file;
CString m_sName;
};

CMemLogFile::CMemLogFile(CString sName)
{
m_sName = sName;
m_file.Open(sName, CFile::modeCreate|CFile::modeWrite);
}

void CMemLogFile::Close()
{
m_file.Close();
CMemFile::Close();
}

void CMemLogFile::Truncate()
{
this->SetLength(0);
}

void CMemLogFile::WriteToDisk()
{
char buf[READ_LEN] = "";
this->SeekToBegin();

int iBytesRead = 0;

do
{
iBytesRead = this->Read(buf, READ_LEN);
m_file.Write(buf, iBytesRead);

} while ( iBytesRead >= READ_LEN);

m_file.Flush();
}

This works fine except for the fact that I don't have the advance
formatting options such as setw() that ofstream provides.

My questions are:
1. Can I control the buffering of an ofstream? (Not using 'endl' and
the default state 'nounitbuf' doesn't seem to work)

2. Failing (1), is there a way that we can increase the buffer size of
an ofstream buffer?

3. How can you reset an ofstream buffer? (Just like CFile::SetLength(0)
truncates)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
where can I find good samples for efficient computation of matrix multiplication? walala VHDL 2 03-24-2010 10:06 AM
Help:efficient FSM coding msd VHDL 1 02-22-2005 02:59 PM
How to implenetment an efficient shifter Fano VHDL 9 10-16-2003 08:58 PM
Hyper-efficient Text Importing Awah Teh ASP .Net 2 09-03-2003 12:50 AM
Pointer Artithmetic on DB_File values: i need it (or a very efficient solution for this problem) Antonio Perl 1 07-09-2003 07:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57