I am creating a small vector paint application. (using pure Win32 API and C)
Up to now it can just draw boxes on the window. A box takes a
typedef struct to store its data (X and Y pos, width and height..). An array to store these data (
typedef struct) is dynamically allocated.
malloc() to allocate memory for that array at the first time.
Whenever a new box is created that array is expanded using
realloc(). And the data for the new box is assigned as
data[last_box] = new_box.
After they are passed to
WM_PAINT to begin panting.
This design works fine ! But the questions are,
1. Is this a good practice, reallocating every time a new box is created.
2. Are there any alternatives, if so which is the best.