You don't need to re-alloc it each time do you? You can just re-fill it each time. Also the buffer you use should not be re-allocated each time either, just when it needs to be grown.