now allocate memory for buffer in heap instead of stack