#include <MemBlob.h>

Inheritance diagram for MemBlob:
Collaboration diagram for MemBlob:

Public Types

typedef RefCount< MemBlobPointer
typedef uint32_t size_type

Public Member Functions

 MemBlob (const size_type reserveSize)
 create a new MemBlob with at least reserveSize capacity More...
 MemBlob (const char *buffer, const size_type bufferSize)
 create a MemBlob containing a copy of the buffer of a given size More...
virtual ~MemBlob ()
size_type spaceSize () const
 the number unused bytes at the end of the allocated blob More...
bool canAppend (const size_type off, const size_type n) const
void appended (const size_type n)
void append (const char *source, const size_type n)
void clear ()
 extends the available space to the entire allocated blob More...
std::ostream & dump (std::ostream &os) const
 dump debugging information More...

Static Public Member Functions

static const MemBlobStatsGetStats ()
 obtain a const view of class-wide statistics More...

Public Attributes

char * mem
 raw allocated memory block More...
size_type capacity
 size of the raw allocated memory block More...
size_type size
 maximum allocated memory in use by callers More...
const InstanceId< MemBlobid
 blob identifier More...

Private Member Functions

void memAlloc (const size_type memSize)
bool isAppendOffset (const size_type off) const
 whether the offset points to the end of the used area More...
bool willFit (const size_type n) const
 whether n more bytes can be appended More...
 MemBlob (const MemBlob &)
MemBloboperator= (const MemBlob &)

Static Private Attributes

static MemBlobStats Stats
 class-wide statistics More...

Detailed Description

Refcountable, fixed-size, content-agnostic memory buffer.

Allocated memory block is divided into two sequential areas: "used memory" and "available space". The used area can be filled during construction, grows via the append() call, and can be clear()ed.

MemBlob users can cooperate to safely share the used area. However, MemBlob provides weak use accounting and no sharing protections besides refcounting.

Definition at line 45 of file MemBlob.h.

Member Typedef Documentation

Definition at line 50 of file MemBlob.h.

typedef uint32_t MemBlob::size_type

Definition at line 51 of file MemBlob.h.

Constructor & Destructor Documentation

MemBlob::MemBlob ( const size_type  reserveSize)

Definition at line 51 of file MemBlob.cc.

References debugs, HERE(), memAlloc(), and MEMBLOB_DEBUGSECTION.

MemBlob::MemBlob ( const char *  buffer,
const size_type  bufferSize 

Definition at line 60 of file MemBlob.cc.

References append(), debugs, HERE(), memAlloc(), and MEMBLOB_DEBUGSECTION.

MemBlob::MemBlob ( const MemBlob )

Member Function Documentation

void MemBlob::append ( const char *  source,
const size_type  n 

copies exactly n bytes from the source to the available space area, enlarging the used area by n bytes

TextExceptionif there is not enough space in the blob
sourceraw buffer to be copied
nthe number of bytes to copy from the source buffer

Definition at line 116 of file MemBlob.cc.

References MemBlobStats::append, mem, Must, size, Stats, and willFit().

Referenced by SBuf::lowAppend(), MemBlob(), and SBuf::reAlloc().

void MemBlob::appended ( const size_type  n)

adjusts internal object state as if exactly n bytes were append()ed

TextExceptionif there was not enough space in the blob
nthe number of bytes that were appended

Definition at line 108 of file MemBlob.cc.

References MemBlobStats::append, Must, size, Stats, and willFit().

bool MemBlob::canAppend ( const size_type  off,
const size_type  n 
) const

check whether the caller can successfully append() n bytes

true the caller may append() n bytes to this blob now
offthe end of the blob area currently used by the caller
nthe total number of bytes the caller wants to append

Definition at line 73 of file MemBlob.h.

References isAppendOffset(), and willFit().

Referenced by SBuf::rawAppendFinish(), and SBuf::rawSpace().

void MemBlob::clear ( )

Definition at line 95 of file MemBlob.h.

References size.

Referenced by SBuf::clear().

std::ostream & MemBlob::dump ( std::ostream &  os) const

Definition at line 134 of file MemBlob.cc.

References capacity, mem, and size.

Referenced by SBuf::dump().

const MemBlobStats & MemBlob::GetStats ( )

Definition at line 128 of file MemBlob.cc.

References Stats.

Referenced by SBufStatsAction::collect(), SBufStats::dump(), and testSBuf::testDumpStats().

bool MemBlob::isAppendOffset ( const size_type  off) const

Definition at line 113 of file MemBlob.h.

References size.

Referenced by canAppend().

void MemBlob::memAlloc ( const size_type  minSize)

Allocate an available space area of at least minSize bytes in size. Must be called by constructors and only by constructors.

Definition at line 89 of file MemBlob.cc.

References MemBlobStats::alloc, capacity, debugs, MemBlobStats::live, MemBlobStats::liveBytes, mem, memAllocString(), MEMBLOB_DEBUGSECTION, Must, size, and Stats.

Referenced by MemBlob().

MemBlob::MEMPROXY_CLASS ( MemBlob  )
MemBlob& MemBlob::operator= ( const MemBlob )
size_type MemBlob::spaceSize ( ) const

Definition at line 65 of file MemBlob.h.

References capacity, and size.

Referenced by SBuf::spaceSize(), and willFit().

bool MemBlob::willFit ( const size_type  n) const

Definition at line 116 of file MemBlob.h.

References spaceSize().

Referenced by append(), appended(), and canAppend().

Member Data Documentation

const InstanceId<MemBlob> MemBlob::id

Definition at line 105 of file MemBlob.h.

MemBlobStats MemBlob::Stats

Definition at line 108 of file MemBlob.h.

Referenced by append(), appended(), GetStats(), memAlloc(), and ~MemBlob().

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






Web Site Translations