Public Member Functions | Protected Member Functions | Protected Attributes
ibis::fileManager::storage Class Reference

The storage class treats all memory as char*. More...

#include <fileManager.h>

Inheritance diagram for ibis::fileManager::storage:
ibis::fileManager::roFile

List of all members.

Public Member Functions

char * begin ()
 Starting address of the storage object.
const char * begin () const
 Starting address of the storage object.
virtual void beginUse ()
 Record a new active reference to this object.
size_t bytes () const
 Return the number of bytes contained in the object.
void copy (const storage &rhs)
 Copy function. Make an in-meory copy following the copy-and-swap idiom.
bool empty () const
 Is the storage object empty?
const char * end () const
 Ending address of the storage object.
virtual void endUse ()
 Record the termination of an active reference.
void enlarge (size_t nelm=0)
 Enlarge the current array by 61.8% if nelm is smaller than the current size, otherwise enlarge to the specified size.
const char * filename () const
 Pointer to the file name supporting this storage object.
unsigned inUse () const
 Number of current accesses to this object.
virtual bool isFileMap () const
 Is the storage a file map ?
storageoperator= (const storage &rhs)
 Assignment operator.
char operator[] (size_t i) const
 Unchecked index operator. Returns the character at position i.
unsigned pastUse () const
 Number of past accesses to this object.
virtual void printStatus (std::ostream &out) const
 Print information about the storage object to the specified output stream.
off_t read (const char *fname, const off_t begin, const off_t end)
 Read a part of a file.
off_t read (const int fdes, const off_t begin, const off_t end)
 Read part of a open file [begin, end). Return the number of bytes read.
size_t size () const
 Return the size (bytes) of the object.
 storage ()
 Constructor. Allocate no real storage.
 storage (size_t n)
 Constructor.
 storage (const char *fname, const off_t begin, const off_t end)
 Constructor. Read part of a file from [begin, end).
 storage (const int fdes, const off_t begin, const off_t end)
 Constructor. Read part of a open file, from [begin, end). The file.
 storage (const char *begin, const char *end)
 Copy constructor. Copy the values between begin and end [begin, end).
 storage (const storage &rhs)
 Copy constructor. Make an in-memory copy.
void swap (storage &rhs) throw ()
 Swap the content of the storage objects.
void write (const char *file) const

Protected Member Functions

virtual void clear ()
 Actually freeing the storage allocated.

Protected Attributes

char * m_begin
 Beginning of the storage.
char * m_end
 End of the storage.
unsigned nacc
 Number of accesses in the past.
char * name
 Name of the file. NULL (0) if no file is involved.
ibis::util::sharedInt32 nref
 Number of (active) references to this storage.

Detailed Description

The storage class treats all memory as char*.

It only uses malloc family of functions to manage the memory allocation and deallocation.

Note:
This class intends to hold a piece of memory managed by ibis::fileManager. If an object of this type is acquired through ibis::fileManager::getFile, the ownership of the object belongs to the file manager, therefore the caller should not delete the object. Of course, the object created through explicit call to a constructor is owned by the user code.

Constructor & Destructor Documentation

ibis::fileManager::storage::storage ( size_t  n) [explicit]

Constructor.

Allocate storage for an array of the specified size (in bytes).

References ibis::gVerbose, ibis::fileManager::instance(), m_begin, m_end, ibis::fileManager::maxBytes, and ibis::fileManager::printStatus().


Member Function Documentation

void ibis::fileManager::storage::enlarge ( size_t  nelm = 0)

Enlarge the current array by 61.8% if nelm is smaller than the current size, otherwise enlarge to the specified size.

Boost the memory allocated for the storage object.

It increases the memory reserved to the specified size (in bytes) or by 61.8% if nelm is 0. It does nothing if the requested size is less than the current size. This implementation uses the copy-and-swap idiom.

References m_begin.

const char* ibis::fileManager::storage::filename ( ) const [inline]

Pointer to the file name supporting this storage object.

It returns nil for in-memory storage.

References name.

Referenced by ibis::array_t< rid_t >::incore(), ibis::pack::read(), and ibis::fileManager::recordFile().

ibis::fileManager::storage & ibis::fileManager::storage::operator= ( const storage rhs)

Assignment operator.

Make an in-memory copy through the copy constructor.

void ibis::fileManager::storage::printStatus ( std::ostream &  out) const [virtual]

Print information about the storage object to the specified output stream.

Reimplemented in ibis::fileManager::roFile.

Referenced by ibis::fileManager::getFileSegment().

off_t ibis::fileManager::storage::read ( const char *  fname,
const off_t  begin,
const off_t  end 
)

Read a part of a file.

The file name is given as the first argument fname, and the range [begin, end) is specified in bytes. Return the number of bytes read.

References ibis::horometer::CPUTime(), ibis::gVerbose, ibis::fileManager::instance(), ibis::util::read(), ibis::horometer::realTime(), ibis::fileManager::recordPages(), ibis::horometer::start(), ibis::horometer::stop(), and UnixOpen.

Referenced by storage().

void ibis::fileManager::storage::swap ( storage rhs) throw () [inline]

Swap the content of the storage objects.

Note:
It does not swap the reference counts! Since changing the storage object requires the client code to update the pointers they hold. The only way this function is used is to reallocate storage for array_t objects. In that case, one of the storage object is a temporary one with a reference count of 0 (zero). It is important to keep that count 0 so the temporary storage object can be freed afterward. Suggested by Zeid Derhally (2010/02).

References m_begin, m_end, nacc, and name.

Referenced by ibis::direkte::append().


Member Data Documentation

unsigned ibis::fileManager::storage::nacc [protected]

Number of accesses in the past.

Referenced by pastUse(), ibis::fileManager::roFile::score(), and swap().


The documentation for this class was generated from the following files:

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive