change data structure, buffer type -> dynamic allocation (not tested!)