diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-30 05:28:06 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-04-30 05:28:06 -0700 |
commit | 8921ce29627b45d78d1870d550418fc3d13dcdbe (patch) | |
tree | 1b5b37a317c93d55247ac3da719a8dcd8eaf072b /match.c | |
parent | fbdb393ae1e2ea5d368e4dda1577a10715e26a75 (diff) | |
download | dartboat-8921ce29627b45d78d1870d550418fc3d13dcdbe.tar.gz dartboat-8921ce29627b45d78d1870d550418fc3d13dcdbe.tar.xz |
grow memory for visits as needed
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -1,13 +1,15 @@ #include "match.h" #include <stdlib.h> +#include <string.h> struct leg *leg_init(int points, char *name) { struct leg *l = calloc(1, sizeof(*l)); l->name = name; l->start = l->rem = points; - l->visits = calloc(1000, sizeof(*(l->visits))); // FIXME + l->size_visits = 16; + l->visits = calloc(l->size_visits, sizeof(*(l->visits))); return l; } @@ -23,3 +25,12 @@ void leg_free(struct leg *l) free(l->visits); free(l); } + +void leg_grow_visits(struct leg *l) +{ + + size_t bytes = l->size_visits * sizeof(*(l->visits)); + l->size_visits *= 2; + l->visits = realloc(l->visits, 2 * bytes); + memset((char *)l->visits + bytes, 0, bytes); +} |