optimize memory allocation