Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

indri::file::SequentialWriteBuffer Class Reference

#include <SequentialWriteBuffer.hpp>

List of all members.

Public Member Functions

 SequentialWriteBuffer (File &file, size_t length)
void seek (UINT64 position)
char * write (size_t length)
void write (const void *buffer, size_t length)
void unwrite (size_t length)
UINT64 tell () const
void flush ()
void flushRegion (UINT64 start, UINT64 length)

Private Attributes

File_file
InternalFileBuffer _current
UINT64 _position
UINT64 _eof


Detailed Description

Wraps an instance of indri::file::File, and provides buffering support. This class works much like the BufferedWriter class in Java; every write is stored in a memory buffer until that buffer fills, then the data is transferred to disk en masse.

There are at least two good reasons to buffer data before writing. The first is to avoid system call overhead for little tiny writes. If this is all you care about, you can keep this write buffer fairly small; perhaps a few kilobytes.

However, a write buffer can also keep the disk from seeking unnecessarily if you're writing to a few files simultaenously. For this kind of application, consider using a megabyte or so. This also helps keep file fragmentation down.


Constructor & Destructor Documentation

indri::file::SequentialWriteBuffer::SequentialWriteBuffer File file,
size_t  length
[inline]
 

Constructs a new instance of the SequentialWriteBuffer class. The file pointer is set to the end of the file.

Parameters:
file The File object to wrap.
length Number of bytes to buffer.


Member Function Documentation

void indri::file::SequentialWriteBuffer::flush  )  [inline]
 

Flushes data in the buffer out to the file.

void indri::file::SequentialWriteBuffer::flushRegion UINT64  start,
UINT64  length
[inline]
 

void indri::file::SequentialWriteBuffer::seek UINT64  position  )  [inline]
 

Seek to position bytes into the file.

UINT64 indri::file::SequentialWriteBuffer::tell  )  const [inline]
 

Returns:
Current file position.

void indri::file::SequentialWriteBuffer::unwrite size_t  length  )  [inline]
 

Move the file pointer back by length bytes, and remove all of those bytes from the buffer. It's as if you didn't write those length bytes at all.

Parameters:
length Number of bytes to unwrite.

void indri::file::SequentialWriteBuffer::write const void *  buffer,
size_t  length
[inline]
 

Writes length bytes of data from buffer into the file.

Parameters:
buffer Buffer containing data to be written to the file.
length Bytes to copy from the buffer into the file.

char* indri::file::SequentialWriteBuffer::write size_t  length  )  [inline]
 

Allocate space in the buffer for some new data. This is roughly equivalent to memory-mapping the next length bytes of the file.

This buffer space is valid until your next call to a SequentialWriteBuffer method.

Parameters:
length Number of bytes to write.
Returns:
Returns a pointer to memory where you can write your data.


Member Data Documentation

InternalFileBuffer indri::file::SequentialWriteBuffer::_current [private]
 

UINT64 indri::file::SequentialWriteBuffer::_eof [private]
 

File& indri::file::SequentialWriteBuffer::_file [private]
 

UINT64 indri::file::SequentialWriteBuffer::_position [private]
 


The documentation for this class was generated from the following file:
Generated on Tue Jun 15 11:03:00 2010 for Lemur by doxygen 1.3.4