The storage class treats all memory as char*. More...
#include <fileManager.h>
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 ? | |
storage & | operator= (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. | |
The storage class treats all memory as char*.
It only uses malloc family of functions to manage the memory allocation and deallocation.
|
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 | ||
) |
|
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.
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().
|
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.
|
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().
|
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.
|
inline |
Swap the content of the storage objects.
References m_begin, m_end, nacc, and name.
Referenced by ibis::direkte::append().