Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

nsAutoBuffer< T, sz > Class Template Reference

#include <nsAutoBuffer.h>

List of all members.


Detailed Description

template<class T, PRInt32 sz>
class nsAutoBuffer< T, sz >

A buffer which will use stack space if the requested size will fit in the stack buffer and allocate from the heap if not.

Below is a usage example :

typedef nsAutoBuffer<PRUnichar, 256> nsAutoUnicharBuffer;

nsAutoUnicharBuffer buffer;

if (!buffer.EnsureElemCapacity(initialLength)) return NS_ERROR_OUT_OF_MEMORY;

PRUnichar *unicharPtr = buffer.get();

// add PRUnichar's to the buffer pointed to by |unicharPtr| as long as // the number of PRUnichar's is less than |intialLength|

// increase the capacity if (!buffer.AddElemCapacity(extraLength)) return NS_ERROR_OUT_OF_MEMORY

unicharPtr = buffer.get() + initialLength;

//continue to add PRUnichar's....

Definition at line 74 of file nsAutoBuffer.h.


Public Member Functions

PRBool AddElemCapacity (PRInt32 inElemCapacity)
PRBool EnsureElemCapacity (PRInt32 inElemCapacity)
T * get () const
PRInt32 GetElemCapacity () const

Protected Attributes

T * mBufferPtr
PRInt32 mCurElemCapacity
mStackBuffer [sz]

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

Generated by  Doxygen 1.6.0   Back to index