Exemple #1
0
node_t *
node_new(void *ptr)
{
  node_t *n;

  n = mem_chunk_alloc(sizeof *n);
  if (n) {
    n->next = NULL;
    n->prev = NULL;
    n->ptr = ptr;
  }
  return n;
}
Exemple #2
0
GAULFUNC boolean ga_chromosome_integer_allocate( population *pop,
                                        entity *embryo )
  {
  int		i;		/* Loop variable over all chromosomes */

  if (!pop) die("Null pointer to population structure passed.");
  if (!embryo) die("Null pointer to entity structure passed.");

  if (embryo->chromosome!=NULL)
    die("This entity already contains chromosomes.");

#ifdef USE_CHROMO_CHUNKS
  THREAD_LOCK(pop->chromo_chunk_lock);
  if (!pop->chromo_chunk)
    {
    pop->chromoarray_chunk = mem_chunk_new(pop->num_chromosomes*sizeof(int *), 1024);
    pop->chromo_chunk = mem_chunk_new(pop->num_chromosomes*pop->len_chromosomes*sizeof(int), 2048); 
    }

  embryo->chromosome = mem_chunk_alloc(pop->chromoarray_chunk);
  embryo->chromosome[0] = mem_chunk_alloc(pop->chromo_chunk);
  THREAD_UNLOCK(pop->chromo_chunk_lock);
#else
  if ( !(embryo->chromosome = s_malloc(pop->num_chromosomes*sizeof(int *))) )
    die("Unable to allocate memory");
  if ( !(embryo->chromosome[0] = s_malloc(pop->num_chromosomes*pop->len_chromosomes*sizeof(int))) )
    die("Unable to allocate memory");
#endif

  for (i=1; i<pop->num_chromosomes; i++)
    {
    embryo->chromosome[i] = &(((int *)embryo->chromosome[i-1])[pop->len_chromosomes]);
    }

  return TRUE;
  }
Exemple #3
0
list_t *
list_new(void)
{
  list_t *list;

  list = mem_chunk_alloc(sizeof *list);
  if (list) {
    static const struct list zero_list;

    *list = zero_list;
    list->stamp = 1;
    LIST_CHECK(list);
  }
  return list;
}
Exemple #4
0
static hash_item_t * 
hash_item_get(hashlist_t *hl, const void *key, void *value)
{
  hash_item_t *item;

  RUNTIME_ASSERT(hl != NULL);

  item = mem_chunk_alloc(sizeof *item);
  if (item) {
    item->bnext = NULL;
    item->value = value;
    item->node.ptr = deconstify_void_ptr(key);
    item->node.prev = NULL;
    item->node.next = NULL;
  }
  return item;
}