#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...
 ~MemBlob () override
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...
void syncSize (const size_type n)
void consume (const size_type n)
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

◆ Pointer

Definition at line 50 of file MemBlob.h.

◆ size_type

typedef uint32_t MemBlob::size_type

Definition at line 51 of file MemBlob.h.

Constructor & Destructor Documentation

◆ MemBlob() [1/3]

MemBlob::MemBlob ( const size_type  reserveSize)

Definition at line 51 of file MemBlob.cc.

References debugs, memAlloc(), and MEMBLOB_DEBUGSECTION.

◆ MemBlob() [2/3]

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

Definition at line 60 of file MemBlob.cc.

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

◆ ~MemBlob()

◆ MemBlob() [3/3]

MemBlob::MemBlob ( const MemBlob )

Member Function Documentation

◆ append()

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 MemBlob(), SBuf::lowAppend(), and SBuf::reAlloc().

◆ appended()

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

◆ canAppend()

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

◆ clear()

void MemBlob::clear ( )

Definition at line 97 of file MemBlob.h.

References size.

Referenced by SBuf::clear().

◆ consume()

void MemBlob::consume ( const size_type  n)

forget the first n bytes, moving the rest of data (if any) to the start forgets all data (i.e. empties the buffer) if n exceeds size

Definition at line 137 of file MemBlob.cc.

References mem, min(), Must, and size.

Referenced by SBuf::cow().

◆ dump()

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

Definition at line 155 of file MemBlob.cc.

References capacity, mem, and size.

Referenced by SBuf::dump().

◆ GetStats()

const MemBlobStats & MemBlob::GetStats ( )

Definition at line 149 of file MemBlob.cc.

References Stats.

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

◆ isAppendOffset()

bool MemBlob::isAppendOffset ( const size_type  off) const

Definition at line 123 of file MemBlob.h.

References size.

Referenced by canAppend().

◆ memAlloc()

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  )

◆ operator=()

MemBlob & MemBlob::operator= ( const MemBlob )

◆ spaceSize()

size_type MemBlob::spaceSize ( ) const

Definition at line 65 of file MemBlob.h.

References capacity, and size.

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

◆ syncSize()

void MemBlob::syncSize ( const size_type  n)

keep the first n bytes and forget the rest of data cannot be used to increase our size; use append*() methods for that

Definition at line 128 of file MemBlob.cc.

References debugs, MEMBLOB_DEBUGSECTION, Must, and size.

Referenced by SBuf::cow().

◆ willFit()

bool MemBlob::willFit ( const size_type  n) const

Definition at line 126 of file MemBlob.h.

References spaceSize().

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

Member Data Documentation

◆ capacity

◆ id

const InstanceId<MemBlob> MemBlob::id

Definition at line 115 of file MemBlob.h.

◆ mem

◆ size

◆ Stats

MemBlobStats MemBlob::Stats

Definition at line 118 of file MemBlob.h.

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

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






Web Site Translations