BBufferGroup::GetBufferList: avoid dynamic allocation

This commit is contained in:
Dario Casalinuovo
2015-07-11 15:40:15 +02:00
parent aa50bf9e9e
commit f50d7408b5
2 changed files with 8 additions and 15 deletions
+2 -2
View File
@@ -316,9 +316,9 @@ VideoConsumer::CreateBuffers(const media_format& withFormat)
} }
} }
BBuffer** buffList = new BBuffer * [3]; BBuffer* buffList[3];
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
buffList[j] = 0; buffList[j] = NULL;
if ((status = fBuffers->GetBufferList(3, buffList)) == B_OK) if ((status = fBuffers->GetBufferList(3, buffList)) == B_OK)
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
+6 -13
View File
@@ -344,25 +344,18 @@ BBufferGroup::AddBuffersTo(BMessage* message, const char* name, bool needLock)
if (name == NULL || strlen(name) == 0) if (name == NULL || strlen(name) == 0)
return B_BAD_VALUE; return B_BAD_VALUE;
BBuffer** buffers; BBuffer* buffers[fBufferCount];
int32 count; status_t status = GetBufferList(fBufferCount, buffers);
count = fBufferCount;
buffers = new BBuffer * [count];
status_t status = GetBufferList(count, buffers);
if (status != B_OK) if (status != B_OK)
goto end; return status;
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < fBufferCount; i++) {
status = message->AddInt32(name, int32(buffers[i]->ID())); status = message->AddInt32(name, int32(buffers[i]->ID()));
if (status != B_OK) if (status != B_OK)
goto end; return status;
} }
end: return B_OK;
delete [] buffers;
return status;
} }