From 1fdc36cd23a44688065347e8075bef910147a6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henriques?= Date: Sun, 1 Nov 2020 00:18:05 +0000 Subject: [PATCH] Made memory allocation more efficient. --- gol.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gol.c b/gol.c index e72af6e..57260bd 100644 --- a/gol.c +++ b/gol.c @@ -85,7 +85,7 @@ p_universe * init_parallel_universes(int total_universes, int uni_cells) { for( int i = 0; i < total_universes; i++ ) { uni = malloc(sizeof(p_universe)); - uni->cells = malloc(uni_cells * sizeof(char)); + uni->cells = malloc((PANEL_W * PANEL_H) * sizeof(char)); randomize_universe(uni, uni_cells); @@ -352,9 +352,10 @@ int main(int argc, char **argv) { last_stuck_check = before; last_reset = before; - destroy_parallel_universes(universe); + //destroy_parallel_universes(universe); init_rand_context(&context); - universe = init_universes_w_context(&context); + //universe = init_universes_w_context(&context); + randomize_universe(universe, context.TOTAL_CELLS); } for (y = 0; y < PANEL_H; y++) { @@ -387,3 +388,4 @@ int main(int argc, char **argv) { return 0; } +