Logo Search packages:      
Sourcecode: ragel version File versions

template<class T, class Resize>
SVector< T, Resize >::SVector ( long  size,
long  allocLen 
) [inline]

Create a vector with a specified number of initial elements and allocation.

Default constructors are used to create the new elements. If the size is greater than allocLen, then the space will be grown according to the allocation scheme. Both size and allocLen are in units of T. If a linear resizer is used, the step defaults to 256 units of T. For a runtime vector both up and down allocation schemes default to Exponential.

Definition at line 314 of file svectcommon.h.

References STable< T >::data, and SVector< T, Resize >::setAsNew().

{
      /* Allocate the space if we are given a positive allocLen. */
      if ( allocLen > 0 ) {
            /* Allocate the data needed. */
            STabHead *head = (STabHead*) malloc( sizeof(STabHead) + 
                        sizeof(T) * allocLen );
            if ( head == 0 )
                  throw std::bad_alloc();

            /* Set up the header and save the data pointer. */
            head->refCount = 1;
            head->allocLen = allocLen;
            head->tabLen = 0;
            BaseTable::data = (T*) (head + 1);
      }

      /* Grow to the size specified. If we did not have enough space
       * allocated that is ok. Table will be grown to the right size. */
      setAsNew( size );
}


Generated by  Doxygen 1.6.0   Back to index