memory buf code