Search wiring.org.co:

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

Class | Vector
Name | ### setSize()
Examples |
    Vector < int > intVector;
    int arrayOfInts[11];  // declares an array of ints with 11 positions

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

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

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

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

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

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

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

    void loop() {

    }
Description | Sets the size of this vector. If the new size is greater than the current size, new null items are added to the end of the vector. If the new size is less than the current size, all components at index newSize and greater are discarded.
Syntax |
    setSize(size)
Parameters |
size | int: the new size of this vector
Usage | Application

Updated on November 01, 2009 05:22:25pm PST