I need to use some low-level C functions provided by a library, to wrap them and provide a 'more high-level layer' ; in this case , my problem is to get a data contained within a buffer, and at least to learn how to do it right, I would like to know what you think would be the thing to do in C++03 AND in C++11.
FYI, I am working under Red Hat Linux, with GCC 4.4.7 (so not really C++11-compliant, http://ift.tt/20V739K).
Here is a snippet of what I am trying to do :
#define DATA_BLOCKS 4096 // the numbers of 16-bit words within the buffer
std::vector<uint16_t> myClass::getData()
{
uint16_t buffer[DATA_BLOCKS];
getDataBuf(fd, dma, am, buffer[]); //C-function provided by the library
// pushing buffer content into vector
std::vector <uint16_t> myData;
for(int i=0; i<DATA_BLOCKS; i++)
myData.pushback(buffer[i]);
return myData;
}
Within the link I provided, I am not able to find if it's a good idea to proceed like in C++11 to return the 'whole' vector.
For a vector, is there a best method to fill 'myData' than using the method 'pushback()' within a loop ?
Aucun commentaire:
Enregistrer un commentaire