我如何在std :: vector <short>?</short>中push_back ShortBuffer数据

时间:2013-06-04 10:29:24

标签: c++

我在ShortBuffer变量中有数据。

我想在push_back std::vector<short>变量中input。我使用了以下代码,但由于for循环很长,应用程序会冻结。

还有其他办法吗?

ShortBuffer *pBuffer1 = pData->AsShortBufferN();

std::vector<short> input(BUFFER_SIZE);

for (int i = 0; i < BUFFER_SIZE-1; ++i) {
    short out1;
    pBuffer1->Get(out1);
    input.push_back(out1);
}

1 个答案:

答案 0 :(得分:1)

如果ShortBufferwhat I think it is,则应该有效:

// Allocate enough space to avoid push_back
std::vector<short> input(BUFFER_SIZE, 0);
// Let the GetArray method do the copying
pBuffer1->GetArray(&input[0], 0, BUFFER_SIZE);
相关问题