I agree with Alex. Mikhail, you will have to allocate this "safe buffer" during prepare step.
I would add to Alex idea that each thread allocates its own "safe buffer" and internal threads do not release this buffer and only enlarge if necessary. Of course, if buffers occasionally grows too large then thread should release extra chunk. --Yakov