Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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

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 storage object. More...
 
const char * filename () const
 Pointer to the file name supporting this storage object. More...
 
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. More...
 
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. More...
 
off_t read (const char *fname, const off_t begin, const off_t end)
 Read a part of a file. More...
 
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.
 
virtual void * release ()
 Release the control of the memory to the caller as a raw pointer. More...
 
size_t size () const
 Return the size (bytes) of the object.
 
 storage ()
 Constructor. Allocate no real storage.
 
 storage (size_t n)
 Constructor. More...
 
 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 (char *addr, size_t num)
 Wrap user provided memory into a storage object. More...
 
 storage (const storage &rhs)
 Copy constructor. Make an in-memory copy.
 
void swap (storage &rhs) throw ()
 Swap the content of the storage objects. More...
 
void write (const char *file) const
 

Protected Member Functions

virtual void clear ()
 Actually freeing the storage allocated. More...
 

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::util::groupby1000(), ibis::fileManager::instance(), m_begin, m_end, ibis::fileManager::maxBytes, ibis::fileManager::printStatus(), and ibis::fileManager::totalBytes.

ibis::fileManager::storage::storage ( char *  addr,
size_t  num 
)

Wrap user provided memory into a storage object.

It does not copy the content, thus the user-provided memory must not be freed while this object is in use.

References m_begin, and name.

Member Function Documentation

void ibis::fileManager::storage::clear ( )
protectedvirtual

Actually freeing the storage allocated.

The storage object is reference counted (through the variable nref). If the reference count is not zer0, this function will only print a warning message, but will not actually attempt to free the memory.

Note
When name is not nil, but *name == 0, then the pointer is given by the user and the user is responsible for freeing the memory.

Reimplemented in ibis::fileManager::roFile.

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

Enlarge the current storage object.

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

References m_begin.

Referenced by ibis::fileManager::getFile(), and ibis::fileManager::tryGetFile().

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(), ibis::fileManager::recordFile(), and ibis::fileManager::unrecordFile().

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::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::release ( )
virtual

Release the control of the memory to the caller as a raw pointer.

The caller is to take control of memory and responsible for freeing it after use.

It can only proceed if there is no other accesses to this object.

Reimplemented in ibis::fileManager::roFile.

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().


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