【发布时间】:2016-06-06 22:29:48
【问题描述】:
我需要使用库提供的一些低级 C 函数来包装它们并提供“更高级的层”;在这种情况下,我的问题是获取缓冲区中包含的数据,至少要学习如何正确地做,我想知道你认为在 C++03 和 C+ 中要做的事情+11。
仅供参考,我在 Red Hat Linux 下工作,使用 GCC 4.4.7(所以不是真正符合 C++11,https://gcc.gnu.org/gcc-4.4/cxx0x_status.html)。
这是我正在尝试做的一个 sn-p:
#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;
}
在我提供的链接中,我无法找到像在 C++11 中那样返回“整个”向量是否是个好主意。
对于向量,是否有比在循环中使用方法“pushback()”填充“myData”的最佳方法?
【问题讨论】:
标签: arrays c++11 gcc vector c++03