Circular File

When I wrote my first article on CodeGuru, Expandable, Data Type-Neutral Buffer Class, I realized that there are lot of people seeking the code for a circular file. Hence, I developed my own circular file implementation, and want to share this. Its interface is very simple. Everything basically revolves around the Addline(CString) method which you use to add a line at a time to the current file.

Constructors:

  • //Create New File with Name "default Log" with 100 Lines
    CCirFile(); 
    
  • //Create File with Name strFile Name But 100 lines
    CCirFile(char * strFileName); 
    
  • //You can specify file Name and File Size
    CCirFile(char * ,int ); 
    

Functions

  • //All file initialization here
    int InitFile(); 
    
  • //You should call this function to add new line at start of file
    int AddLine( CString );  
    

Limitations

  • It's not a true circular file implementation. It adds each new line to the beginning of the file, and moves the remaining lines, truncating the last line
  • It's slow and performance could be dramatically increased via the use of multiple threads.

Downloads

Download demo project - 28 Kb


Comments

  • Interesting, but what limitations :(

    Posted by Legacy on 07/09/2002 12:00am

    Originally posted by: C�dric

    Your implementation is interesting and even more because you're cool guy  who shares it.
    
    

    As you said, the 'AddLine()' is slow and doesn't produce a real circular file. So an easy way to improve it erasing this two limitations is to use the next ZwXxx Routines of the MSDN Library :

    - ZwCreateFile()
    - ZwWriteFile() and ByteOffset args
    - ZwQueryInformationFile() and FILE_STANDARD_INFORMATION
    - ZwClose()

    Indeed, you can limit the size of the file thanks to an if_then_else instruction and the ZwQueryInformationFile Routine. Then, the args ByteOffset allow to write from a selected byte in the file. So you can simply implement a real circular file.

    Thanks, bye. ;o)

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds