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

  • A help desk is critical to the operations of an IT services business. As a centralized intake location for technical issues, it allows for a responsive and timely solution to get clients and their staff back to business as usual. In addition to handling immediate IT issues, a help desk performs several proactive tasks to ensure clients' IT systems remain operational and downtime is minimized. Thus, utilizing a help desk and following best practices can improve the productivity, efficiency and satisfaction of …

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds