# How to use vectors to set attributes

Intended audience: developers, Programming language: c++

This page contains examples on how to use C++ vectors to set attribute values on the servers side.

Warning

Tango is optimized not to copy data. For this reason all the attribute set_value() methods only take pointers as input. If you are going to use C++ vectors, you should be aware of the fact that you are going to copy the data! This might slow down execution time when working with large amount of data.

Examples for a vector of short and a vector of string:

     1void MyClass::read_Spectrum(Tango::Attribute &attr)
     2{
     3    DEBUG_STREAM << "MyClass::read_Spectrum() entering... "<< endl;
     4
     5    vector<Tango::DevShort> val;
     6    val.push_back(1);
     7    val.push_back(2);
     8    val.push_back(3);
     9
    10    // data copy !!
    11    Tango::DevVarShortArray tmp_seq;
    12    tmp_seq << val;
    13
    14    attr.set_value (tmp_seq.get_buffer(), tmp_seq.length());
    15}

     1void MyClass::read_StringSpectrum(Tango::Attribute &attr)
     2{
     3    DEBUG_STREAM << "MyClass::read_StringSpectrum() entering... "<< endl;
     4
     5    vector<string> val;
     6    val.push_back("Hello");
     7    val.push_back("cruel");
     8    val.push_back("world!");
     9
    10    // data copy !!
    11    Tango::DevVarStringArray tmp_seq;
    12    tmp_seq << val;
    13
    14    attr.set_value (tmp_seq.get_buffer(), tmp_seq.length());
    15}