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: August 13, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT If you are developing applications, you'll want to join us to learn how applications are changing as a result of gesture recognition. This technology will change how you and your users interact - not simply with your devices, but with the world around you. Your devices will be able to see and hear what your users are doing. Are your applications ready for this? Join us to learn about Intel® RealSense™ Technology, including never been …

  • Live Event Date: July 30, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this upcoming eSeminar that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds