Exemple #1
0
void
_ihash_grow (_ihash_table *htp, const size_t eos)
{
  u_int nbuckets;
  void **ntab;
  void *p, *np;
  size_t i;

  nbuckets = exp2primes[log2c(htp->buckets)+1];
  if (nbuckets < 3)
    nbuckets = 3;

  ntab = New (void * [nbuckets]);
  bzero (ntab, nbuckets * sizeof (*ntab));

  for (i = 0; i < htp->buckets; i++)
    for (p = htp->tab[i]; p; p = np) {
      _ihash_entry *htep = hteof (p);
      size_t ni = htep->val % nbuckets;
      np = htep->next;

      htep->next = ntab[ni];
      htep->pprev = &ntab[ni];
      if (ntab[ni])
	hteof(ntab[ni])->pprev = &htep->next;
      ntab[ni] = p;
    }

  delete[] htp->tab;
  htp->tab = ntab;
  htp->buckets = nbuckets;
}
Exemple #2
0
inline u_int
calc_l_size (size_t mms)
{
  u_int r = log2c (mms);
  if (r > 4)
    return r - 4;
  else
    return 1;
}
Exemple #3
0
void
arena::newchunk (size_t bytes)
{
  char *c;
#ifndef DMALLOC
  if (bytes < size)
    bytes = size;
  size = (1 << (log2c (bytes + MALLOCRESV) + 1)) - MALLOCRESV;
#else /* DMALLOC */
  /* Malloc each chunk seperately so dmalloc catches overrun bugs */
  size = bytes + resv;
#endif /* DMALLOC */
  avail = size - resv;
  c = (char *) xmalloc (size);
  *(void **) c = chunk;
  chunk = c;
  cur = c + resv;
  assert (bytes <= avail);
}
Exemple #4
0
static inline size_t
size (size_t n)
{
  return n ? (1 << log2c (n + MALLOCRESV)) - MALLOCRESV : 0;
}