Salamandar Salamandar - 1 month ago 12
C++ Question

Most efficient way to write a buffer

I have to write an audio buffer that is filled/read progressively.

For now i'm using

m_outputBuffer.erase(
m_outputBuffer.begin(),
m_outputBuffer.begin()+read_samples);


when
read_samples
samples have been read from the buffer (I have to clear it to free RAM).
But I know
erase()
is very expensive so what alternative do I have, considering I basically only have to move the pointer to the first element of my buffer and free the beginning ?

Answer

Finally I'm still using

m_outputBuffer.erase(
            m_outputBuffer.begin(),
            m_outputBuffer.begin()+read_samples);

as it's really efficient : the erasing is done in one chunk, and the data left is relocated at the beginning of my vector, thus no pointer changes.