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 |

### trimToSize()

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 | Trims the capacity of this vector to be the vector's current size. If the capacity of this vector is larger than its current size, then the capacity is changed to equal the size by replacing its internal data array with a smaller one. An application can use this operation to minimize the storage of a vector.
Syntax |
    trimToSize()
Usage | Application

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