2

我在ShortBuffer变量中有数据。

我想push_backstd::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);
}
4

1 回答 1

1

如果ShortBuffer我认为的那样,这应该有效:

// 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);
于 2013-06-04T10:40:11.770 回答