Polaris: MemBuf Class Reference

MemBuf Class Reference

a lazy memory buffer handler More...

#include <MemBuf.h>

List of all members.

Public Member Functions

 MemBuf ()
 ~MemBuf ()
void append (const void *buf, int len)
void append_empty (int len)
void delete_from_end (int len_to_delete)
void compress ()
 Get rid of extra, unneeded space by reducing the amount of memory actually held to exactly that needed.
void * data_ref () const
int len () const
void reset ()
 Clears (deletes !!!) its memory buffer and starts over with zero length.
void * give_up_data ()
 This function causes the MemBuf to give up its hold on its allocated memory -- it returns a pointer to it and nulls out its own buffer -- thus the responsibility for deleting this memory becomes the responsibility of the person who grabs it -- there will be exactly len() bytes returned.

Friends

ostream & operator<< (ostream &o, const MemBuf &mb)


Detailed Description

a lazy memory buffer handler

Polaris C++ VDL

See also:
MemBuf.h

MemBuf.cc

MemBuf.h

Description

The lazy MemBuf class is intended for managing a buffer of memory and is very liberal in gathering memory. That is, when things are appended to MemBuf, it grabs (much) more memory than it actually needs in the hope of reducing the time spent overall in allocating and copying memory. It is also lazy about deallocating memory. When the appending is done and the MemBuf is in its final form, use the method compress() to free up the extra memory that it has grabbed.

Definition at line 33 of file MemBuf.h.


Constructor & Destructor Documentation

MemBuf::MemBuf  )  [inline]
 

Definition at line 79 of file MemBuf.h.

MemBuf::~MemBuf  )  [inline]
 

Definition at line 86 of file MemBuf.h.


Member Function Documentation

void MemBuf::append const void *  buf,
int  len
[inline]
 

< Now append the new data

Definition at line 109 of file MemBuf.h.

References append_empty().

void MemBuf::append_empty int  len  )  [inline]
 

< We need more memory

Definition at line 94 of file MemBuf.h.

Referenced by append().

void MemBuf::delete_from_end int  len_to_delete  ) 
 

... Go ahead and reduce the length

... If the current allocated memory amount is greater than the square ... of 1.5 times the current length, we ought to go ahead and reduce ... the allocated memory. (The reason for the square in the ... computation is that we want to reduce that chance that the next ... immediate insertion after reducing the allocated memory doesn't force ... more memory to be allocated again. Thus we only reduce the memory ... amount to 1.5 times the current length.)

... (may be zero)

Definition at line 53 of file MemBuf.cc.

void MemBuf::compress  )  [inline]
 

Get rid of extra, unneeded space by reducing the amount of memory actually held to exactly that needed.

This should be done when it is likely that the object will not be needing appending again (or at least not in the near future).

Definition at line 122 of file MemBuf.h.

Referenced by give_up_data().

void * MemBuf::data_ref  )  const [inline]
 

Definition at line 128 of file MemBuf.h.

Referenced by list_pu_store(), read_pu(), retrieve_pu(), and setup_to_return_handle().

int MemBuf::len  )  const [inline]
 

Definition at line 134 of file MemBuf.h.

Referenced by list_pu_store(), read_pu(), retrieve_pu(), and setup_to_return_handle().

void MemBuf::reset  ) 
 

Clears (deletes !!!) its memory buffer and starts over with zero length.

Definition at line 94 of file MemBuf.cc.

void * MemBuf::give_up_data  ) 
 

This function causes the MemBuf to give up its hold on its allocated memory -- it returns a pointer to it and nulls out its own buffer -- thus the responsibility for deleting this memory becomes the responsibility of the person who grabs it -- there will be exactly len() bytes returned.

(Be sure to check the len() FIRST before calling this function or you won't be able to tell how) much is there.

Definition at line 81 of file MemBuf.cc.

References compress().


Friends And Related Function Documentation

ostream& operator<< ostream &  o,
const MemBuf mb
[friend]
 

Definition at line 14 of file MemBuf.cc.


The documentation for this class was generated from the following files:
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:07:47 2005