There is nothing more than malloc/free in C. Allocating data is slow, so do it as less as possible.