Search wiring.org.co:

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Class | Vector
Name |

### ensureCapacity()

Examples |
    Vector < int > intVector;
    // declares an array of ints with 11 positions
    int arrayOfInts[11];

    void setup() {
      Serial.begin(9600);
      // turn ON wiring hardware LED
      pinMode(WLED, OUTPUT);
      digitalWrite(WLED, HIGH);

      // add 10 elements from 0 to 10
      for (int i=0; i<10; i++) {
        intVector.addElement(i);
      }

      // copy the Vector content into an array
      intVector.copyInto(arrayOfInts);

      Serial.print("The arrayOfInts elements are: ");
      // print all all elements in the array
      for (int i=0; i<10; i++) {
        Serial.print(arrayOfInts[i], DEC);
        Serial.print(" ");
      }
      Serial.println();

      Serial.print("The vector's capacity is: ");
      // print the vector's capacity
      Serial.println(intVector.capacity(), DEC);

      intVector.ensureCapacity(20);
      Serial.print("now the vector's capacity is: ");
      // print the vector's capacity
      Serial.println(intVector.capacity(), DEC);

      Serial.print("The vector's size is: ");
      // print the vector's size
      Serial.println(intVector.size(), DEC);

      intVector.setSize(5);
      Serial.print("now the vector's size is: ");
      // print the vector's size
      Serial.println(intVector.size(), DEC);

      Serial.print("The vector's capacity is: ");
      // print the vector's capacity
      Serial.println(intVector.capacity(), DEC);
      intVector.trimToSize();
      Serial.print("now the vector's capacity is: ");
      // print the vector's capacity
      Serial.println(intVector.capacity(), DEC);
    }

    void loop() {

    }

Description | Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument. If the current capacity of this vector is less than minCapacity, then its capacity is increased by replacing its internal data array with a larger one. The size of the new data array will be the old size plus the capacity increment, unless the value of capacity increment is less than or equal to zero, in which case the new capacity will be twice the old capacity; but if this new size is still smaller than minCapacity, then the new capacity will be minCapacity.
Syntax |
    ensureCapacity(minCapacity)
Parameters |

minCapacity | minCapacity: int, the vector's minimum capacity

Usage | Application

Updated on July 07, 2011 11:09:24pm PDT