LLHeapBuffer Class Reference

A large contiguous buffer allocated on the heap with new[]. More...

#include <llbuffer.h>

Inheritance diagram for LLHeapBuffer:

Inheritance graph
[legend]
Collaboration diagram for LLHeapBuffer:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 LLHeapBuffer ()
 Construct a heap buffer with a reasonable default size.
 LLHeapBuffer (S32 size)
 Construct a heap buffer with a specified size.
 LLHeapBuffer (const U8 *src, S32 len)
 Construct a heap buffer of minimum size len, and copy from src.
virtual ~LLHeapBuffer ()
 Simple destruction.
S32 bytesLeft () const
 Get the number of bytes left in the buffer.
virtual bool createSegment (S32 channel, S32 size, LLSegment &segment)
 Generate a segment for this buffer.
virtual bool reclaimSegment (const LLSegment &segment)
 reclaim a segment from this buffer.
virtual bool containsSegment (const LLSegment &segment) const
 Test if a segment is inside this buffer.
virtual S32 capacity () const
 Return the current number of bytes allocated.

Protected Attributes

U8mBuffer
S32 mSize
U8mNextFree
S32 mReclaimedBytes

Private Member Functions

void allocate (S32 size)
 Helper method to allocate a buffer and correctly set intertnal state of this buffer.

Detailed Description

A large contiguous buffer allocated on the heap with new[].

This class is a simple buffer implementation which allocates chunks off the heap. Once a buffer is constructed, it's buffer has a fixed length.

Definition at line 202 of file llbuffer.h.


Constructor & Destructor Documentation

LLHeapBuffer::LLHeapBuffer (  ) 

Construct a heap buffer with a reasonable default size.

LLHeapBuffer

Definition at line 103 of file llbuffer.cpp.

References allocate(), LLMemType::MTYPE_IO_BUFFER, and S32.

LLHeapBuffer::LLHeapBuffer ( S32  size  )  [explicit]

Construct a heap buffer with a specified size.

Parameters:
size The minimum size of the buffer.

Definition at line 114 of file llbuffer.cpp.

References allocate(), and LLMemType::MTYPE_IO_BUFFER.

LLHeapBuffer::LLHeapBuffer ( const U8 src,
S32  len 
)

Construct a heap buffer of minimum size len, and copy from src.

Parameters:
src The source of the data to be copied.
len The minimum size of the buffer.

Definition at line 124 of file llbuffer.cpp.

References allocate(), mBuffer, and LLMemType::MTYPE_IO_BUFFER.

LLHeapBuffer::~LLHeapBuffer (  )  [virtual]

Simple destruction.

Definition at line 142 of file llbuffer.cpp.

References mBuffer, mNextFree, mSize, LLMemType::MTYPE_IO_BUFFER, and NULL.


Member Function Documentation

void LLHeapBuffer::allocate ( S32  size  )  [private]

Helper method to allocate a buffer and correctly set intertnal state of this buffer.

Definition at line 215 of file llbuffer.cpp.

References mBuffer, mNextFree, mReclaimedBytes, mSize, and LLMemType::MTYPE_IO_BUFFER.

Referenced by LLHeapBuffer().

S32 LLHeapBuffer::bytesLeft (  )  const

Get the number of bytes left in the buffer.

Note that this is not a virtual function, and only available in the LLHeapBuffer as a debugging aid.

Returns:
Returns the number of bytes left.

Definition at line 151 of file llbuffer.cpp.

References mBuffer, mNextFree, and mSize.

virtual S32 LLHeapBuffer::capacity (  )  const [inline, virtual]

Return the current number of bytes allocated.

Implements LLBuffer.

Definition at line 281 of file llbuffer.h.

References mSize.

bool LLHeapBuffer::containsSegment ( const LLSegment segment  )  const [virtual]

Test if a segment is inside this buffer.

Parameters:
segment The contiguous buffer segment to test.
Returns:
Returns true if the segment is in the bufffer.

Implements LLBuffer.

Definition at line 203 of file llbuffer.cpp.

References LLSegment::data(), mBuffer, mSize, and LLSegment::size().

Referenced by reclaimSegment().

bool LLHeapBuffer::createSegment ( S32  channel,
S32  size,
LLSegment segment 
) [virtual]

Generate a segment for this buffer.

The segment returned is always contiguous memory. This call can fail if no contiguous memory is available, eg, offset is past the end. The segment returned may be smaller than the requested size. It is up to the caller to delete the segment returned.

Parameters:
channel The channel for the segment.
offset The offset from zero in the buffer
size The requested size of the segment
segment[out] The out-value from the operation
Returns:
Returns true if a segment was found.

Implements LLBuffer.

Definition at line 157 of file llbuffer.cpp.

References llmin(), mBuffer, mNextFree, mSize, LLMemType::MTYPE_IO_BUFFER, and S32.

bool LLHeapBuffer::reclaimSegment ( const LLSegment segment  )  [virtual]

reclaim a segment from this buffer.

This method is called on a buffer object when a caller is done with a contiguous segment of memory inside this buffer. Since segments can be cut arbitrarily outside of the control of the buffer, this segment may not match any segment returned from createSegment(). This call will fail if the segment passed in is note completely inside the buffer, eg, if the segment starts before this buffer in memory or ends after it.

Parameters:
segment The contiguous buffer segment to reclaim.
Returns:
Returns true if the call was successful.

Implements LLBuffer.

Definition at line 179 of file llbuffer.cpp.

References containsSegment(), llendl, llwarns, mBuffer, mNextFree, mReclaimedBytes, mSize, and LLSegment::size().


Member Data Documentation

U8* LLHeapBuffer::mBuffer [protected]

Definition at line 284 of file llbuffer.h.

Referenced by allocate(), bytesLeft(), containsSegment(), createSegment(), LLHeapBuffer(), reclaimSegment(), and ~LLHeapBuffer().

U8* LLHeapBuffer::mNextFree [protected]

Definition at line 286 of file llbuffer.h.

Referenced by allocate(), bytesLeft(), createSegment(), reclaimSegment(), and ~LLHeapBuffer().

S32 LLHeapBuffer::mReclaimedBytes [protected]

Definition at line 287 of file llbuffer.h.

Referenced by allocate(), and reclaimSegment().

S32 LLHeapBuffer::mSize [protected]

Definition at line 285 of file llbuffer.h.

Referenced by allocate(), bytesLeft(), capacity(), containsSegment(), createSegment(), reclaimSegment(), and ~LLHeapBuffer().


The documentation for this class was generated from the following files:
Generated on Thu Jul 1 06:11:23 2010 for Second Life Viewer by  doxygen 1.4.7