Checks buffer size and reallocate if necessary
if (buf[0] + capacity >= buf.length) {
int length = buf[0] + (capacity > RECT_CAPACITY ? capacity : RECT_CAPACITY);
int[] tmp = new int[length];
System.arraycopy(buf, 0, tmp, 0, buf[0]);
buf = tmp;
}
buf[0] += capacity;
return buf;