Reference for Wiring version 0023+. 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 | ensureCapacity() |
||
| 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 | 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 |
|
||
| Usage | Application |

