Closed blnked closed 9 years ago
found one way but I'm not sure that optimal way
bufferSize = 'new buffer size';
int32_t availableToReadBytes;
uint8_t *tempBuffer = TPCircularBufferTail(&buffer, &availableToReadBytes);
printf("+ availableToReadBytes %d \n", availableToReadBytes);
SInt16 *newBuffer = (SInt16*)malloc(sizeof(SInt16)*availableToReadBytes);
memcpy(newBuffer, tempBuffer, availableToReadBytes);
TPCircularBufferCleanup(&buffer);
TPCircularBufferInit(&buffer, bufferSize);
TPCircularBufferProduceBytes(&buffer, newBuffer, availableToReadBytes);
printf("buffer size was changed on %d \n", bufferSize);
// check how many bytes is available
int32_t bytesToRead;
TPCircularBufferTail(&buffer, &bytesToRead);
printf("+ bytesToRead %d \n", availableToReadBytes);
One warning - if you're doing this on the fly, manipulating the buffer like that kinda breaks it's thread-safeness. Unless this isn't on the fly and you're not using it at the time you're resizing - then that's okay.
On 15 Feb 2015, at 8:37 am, Eduard Beleninik notifications@github.com wrote:
found one way but I'm not sure that optimal way
bufferSize = 'new buffer size';
int32_t availableToReadBytes; uint8_t *tempBuffer = TPCircularBufferTail(&buffer, &availableToReadBytes); printf("+ availableToReadBytes %d \n", availableToReadBytes);
SInt16 newBuffer = (SInt16)malloc(sizeof(SInt16)*availableToReadBytes); memcpy(newBuffer, tempBuffer, availableToReadBytes);
TPCircularBufferCleanup(&buffer);
TPCircularBufferInit(&buffer, bufferSize);
TPCircularBufferProduceBytes(&buffer, newBuffer, availableToReadBytes); printf("change buffer %d on size: %d \n", buffer_size_default, bufferSize);
// check how many bytes is available int32_t bytesToRead; TPCircularBufferTail(&buffer, &bytesToRead); printf("+ bytesToRead %d \n", availableToReadBytes); — Reply to this email directly or view it on GitHub.
quick note for who are trying to do something similar
please review your app architecture again. probably you won't to think in future that buffer size changing is a good idea. I hope that's help you keep time.
Any way to change buffer size (existing buffer)
thanks