-- Fixed buf std bad alloc due to use of Int as Index, using std::ptrdiff_t