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 | trimToSize() |
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 | 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 |