Commit 7f402e21 authored by Maria Matejka's avatar Maria Matejka
Browse files

Memory blocks are allocated either from pool slabs or as whole pages

parent 0877d5cf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ ca_lookup(pool *p, const char *name, int f_type)

    if (id >= ca_storage_max) {
      ca_storage_max *= 2;
      ca_storage = mb_realloc(ca_storage, sizeof(struct ca_storage *) * ca_storage_max * 2);
      ca_storage = mb_realloc(&root_pool, ca_storage, sizeof(struct ca_storage *) * ca_storage_max * 2);
    }

    cas = mb_allocz(&root_pool, sizeof(struct ca_storage) + strlen(name) + 1);
+1 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ typedef struct buffer {
  byte *start;
  byte *pos;
  byte *end;
  struct pool *pool;
} buffer;

#define STACK_BUFFER_INIT(buf,size)		\
+5 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ bmap_init(struct bmap *b, pool *p, uint size)
{
  b->size = BIRD_ALIGN(size, 4);
  b->data = mb_allocz(p, b->size);
  b->pool = p;
}

void
@@ -42,7 +43,7 @@ bmap_grow(struct bmap *b, uint need)

  uint old_size = b->size;
  b->size = size;
  b->data = mb_realloc(b->data, b->size);
  b->data = mb_realloc(b->pool, b->data, b->size);

  ASSERT(size >= old_size);
  memset(b->data + (old_size / 4), 0, size - old_size);
@@ -79,6 +80,8 @@ hmap_init(struct hmap *b, pool *p, uint size)
  b->data[3] = b->root;

  memset(b->root, 0, sizeof(b->root));

  b->pool = p;
}

static void
@@ -92,7 +95,7 @@ hmap_grow(struct hmap *b, uint need)
  {
    uint old_size = b->size[i];
    b->size[i] = size;
    b->data[i] = mb_realloc(b->data[i], b->size[i]);
    b->data[i] = mb_realloc(b->pool, b->data[i], b->size[i]);

    ASSERT(size >= old_size);
    memset(b->data[i] + (old_size / 4), 0, size - old_size);
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ struct bmap
{
  u32 size;
  u32 *data;
  pool *pool;
};

void bmap_init(struct bmap *b, pool *p, uint size);
@@ -42,6 +43,7 @@ static inline void bmap_clear(struct bmap *b, uint n)

struct hmap
{
  pool *pool;
  u32 size[4];
  u32 *data[4];
  u32 root[8];
+6 −12
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
#include "lib/resource.h"
#include "sysdep/config.h"

#define BUFFER_(type)		struct { type *data; uint used, size; }
#define BUFFER_(type)		struct { pool *pool; type *data; uint used, size; }
#define BUFFER_TYPE(v)		typeof(* (v).data)
#define BUFFER_SIZE(v)		((v).size * sizeof(* (v).data))

@@ -21,18 +21,19 @@
#define BUFFER(type) BUFFER_(type)
#endif

#define BUFFER_INIT(v,pool,isize)					\
#define BUFFER_INIT(v,_pool,_size)					\
  ({									\
    (v).used = 0;							\
    (v).size = (isize);							\
    (v).data = mb_alloc(pool, BUFFER_SIZE(v));				\
    (v).size = (_size);							\
    (v).data = mb_alloc(_pool, BUFFER_SIZE(v));				\
    (v).pool = _pool;							\
  })

#define BUFFER_SET(v,nsize)						\
  ({									\
    (v).used = (nsize);							\
    if ((v).used > (v).size)						\
      buffer_realloc((void **) &((v).data), &((v).size), (v).used, sizeof(* (v).data)); \
      buffer_realloc((v).pool, (void **) &((v).data), &((v).size), (v).used, sizeof(* (v).data)); \
  })

#define BUFFER_INC(v,step)						\
@@ -55,11 +56,4 @@
#define BUFFER_WALK(v,n)						\
  for (BUFFER_TYPE(v) *_n = (v).data, n; _n < ((v).data + (v).used) && (n = *_n, 1); _n++)

#define BUFFER_SHALLOW_COPY(dst, src)					\
  ({									\
    (dst).used = (src).used;						\
    (dst).size = (src).size;						\
    (dst).data = (src).data;						\
  })

#endif /* _BIRD_BUFFER_H_ */
Loading