/* DLIFE Copyright (C) 2000 Richard W.M. Jones * and other authors listed in the ``AUTHORS'' file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: state.c,v 1.2 2002/04/05 16:47:13 rich Exp $ */ #include "config.h" #include #include #include "state.h" #include "soup.h" #include "cell.h" struct state * state_malloc (int _soup_size, int thread_num) { struct state *p = malloc (sizeof (struct state)); if (p == 0) { perror ("malloc"); abort (); } p->cell_cycle = 0; p->nr_cells_alive = 0; p->nr_cells_allocated = 0; dlink_list_init (&p->alive_list, offsetof (struct cell, next)); dlink_list_init (&p->best_list, offsetof (struct cell, worse)); soup_init (p, _soup_size); p->filename = 0; p->thread_num = thread_num; return p; } void state_free (struct state *state) { struct cell *p; /* Free up cells. This also cleans up soup frags. */ for (p = (struct cell *) state->alive_list.first; p; p = p->next) { cell_kill (state, p); } /* Free up soup. */ free (state->soup); /* Free up soup image filename. */ if (state->filename) free (state->filename); /* Free up structure. */ free (state); }