142 _vec_len (h->
elts)--;
287 uword b, fb, f_size, f_index;
306 if ((s = f_size - size) >= 0)
382 _heap_alloc (
void *v,
403 align_size =
size + align - 1;
416 if (max_len && offset + align_size > max_len)
423 (offset + align_size) * elt_bytes,
426 _vec_len (v) += align_size;
448 uword new_offset, old_offset;
451 new_offset = (old_offset + align - 1) & ~(align - 1);
453 e_index = e - h->
elts;
456 if (new_offset > old_offset)
459 before_e->
offset = old_offset;
464 if (new_offset +
size < old_offset + align_size)
472 e = h->
elts + e_index;
486 *offset_return = e->
offset;
487 *handle_return = e - h->
elts;
491 *offset_return = *handle_return = ~0;
513 e = h->
elts + handle;
525 uword total_size,
i, b, tb, ti, i_last, g_offset;
537 for (i = 0, e = e0; 1; e =
heap_next (e), i++)
562 g.index = g.bin_index = 0;
563 for (i = 0; i <= i_last; i++)
583 for (i = 0; i <= i_last; i++)
584 if (g.index != f[i].index)
636 bytes =
sizeof (h[0]);
663 for (j = 0; j < n / 2; j++)
672 for (j = 0; j < n / 2; j++)
680 s =
format (s,
"index %4d, free\n", e - h->
elts);
684 s =
format (s,
"index %4d, used\n", e - h->
elts);
696 void *v = va_arg (*va,
void *);
701 memset (&zero, 0,
sizeof (zero));
710 s =
format (s,
"heap %p, %6d objects, size %.1fk + overhead %.1fk\n",
712 (overhead_bytes - elt_bytes) / 1024);
729 uword used_count, total_size;
730 uword free_count, free_size;
738 free_size = free_count = 0;
753 uword elt_free_size, elt_free_count;
755 used_count = total_size = elt_free_size = elt_free_count = 0;
756 for (e =
first (h); 1; e = n)
780 ASSERT (free_count == elt_free_count);
781 ASSERT (free_size == elt_free_size);
783 ASSERT (total_size == vec_len (v));
789 for (i = o = 0; 1; i++)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static heap_elt_t * elt_at(heap_header_t *h, uword i)
static heap_elt_t * search_free_list(void *v, uword size)
sll srl srl sll sra u16x4 i
static uword bin_to_size(uword bin)
static uword heap_get_max_len(void *v)
static void elt_delete(heap_header_t *h, heap_elt_t *e)
#define HEAP_LOG2_SMALL_BINS
static uword get_free_elt(void *v, heap_elt_t *e, uword *bin_result)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static heap_elt_t * last(heap_header_t *h)
u8 * format_heap(u8 *s, va_list *va)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
static void elt_insert_before(heap_header_t *h, heap_elt_t *e, heap_elt_t *new)
#define vec_bytes(v)
Number of data bytes in vector.
static heap_elt_t * elt_new(heap_header_t *h)
static void set_free_elt(void *v, heap_elt_t *e, uword fi)
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
static uword heap_is_free(heap_elt_t *e)
#define vec_end(v)
End (last data address) of vector.
static void remove_free_block(void *v, uword b, uword i)
static heap_elt_t * heap_next(heap_elt_t *e)
static heap_elt_t * first(heap_header_t *h)
static void dealloc_elt(void *v, heap_elt_t *e)
uword heap_bytes(void *v)
static u32 * elt_data(void *v, heap_elt_t *e)
static void combine_free_blocks(void *v, heap_elt_t *e0, heap_elt_t *e1)
#define vec_free(V)
Free vector's memory (no header).
static uword heap_offset(heap_elt_t *e)
static uword max_pow2(uword x)
#define vec_capacity(v, b)
Total number of bytes that can fit in vector with current allocation.
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
static void elt_insert_after(heap_header_t *h, heap_elt_t *e, heap_elt_t *new)
void heap_validate(void *v)
void heap_dealloc(void *v, uword handle)
#define clib_bitmap_free(v)
Free a bitmap.
static uword heap_elt_size(void *v, heap_elt_t *e)
static heap_header_t * heap_header(void *v)
static u8 * debug_elt(u8 *s, void *v, word i, word n)
static heap_elt_t * heap_prev(heap_elt_t *e)
uword heap_len(void *v, word handle)
#define vec_elt(v, i)
Get vector value at index i.
static uword clib_bitmap_count_set_bits(uword *ai)
Return the number of set bits in a bitmap.
template key/value backing page structure
#define HEAP_ELT_FREE_BIT
#define vec_free_h(V, H)
Free vector's memory (general version)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static uword max_log2(uword x)
struct clib_bihash_value offset
template key/value backing page structure
static uword size_to_bin(uword size)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".