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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds