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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds