Framework (A-Z)

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

setSize()

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 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 July 07, 2011 11:09:30pm PDT

Creative Commons License