142 _vec_len (h->
elts)--;
287 uword b, fb, f_size, f_index;
307 if ((s = f_size - size) >= 0)
386 _heap_alloc (
void *v,
407 align_size =
size + align - 1;
420 if (max_len && offset + align_size > max_len)
427 (offset + align_size) * elt_bytes,
430 _vec_len (v) += align_size;
452 uword new_offset, old_offset;
455 new_offset = (old_offset + align - 1) & ~(align - 1);
457 e_index = e - h->
elts;
460 if (new_offset > old_offset)
463 before_e->
offset = old_offset;
468 if (new_offset +
size < old_offset + align_size)
476 e = h->
elts + e_index;
490 *offset_return = e->
offset;
491 *handle_return = e - h->
elts;
495 *offset_return = *handle_return = ~0;
517 e = h->
elts + handle;
529 uword total_size,
i,
b, tb, ti, i_last, g_offset;
541 for (i = 0, e = e0; 1; e =
heap_next (e), i++)
566 g.index = g.bin_index = 0;
567 for (i = 0; i <= i_last; i++)
587 for (i = 0; i <= i_last; i++)
588 if (g.index != f[i].index)
640 bytes =
sizeof (h[0]);
667 for (j = 0; j < n / 2; j++)
676 for (j = 0; j < n / 2; j++)
684 s =
format (s,
"index %4d, free\n", e - h->
elts);
688 s =
format (s,
"index %4d, used\n", e - h->
elts);
700 void *v = va_arg (*va,
void *);
714 s =
format (s,
"heap %p, %6d objects, size %.1fk + overhead %.1fk\n",
716 (overhead_bytes - elt_bytes) / 1024);
733 uword used_count, total_size;
734 uword free_count, free_size;
742 free_size = free_count = 0;
757 uword elt_free_size, elt_free_count;
759 used_count = total_size = elt_free_size = elt_free_count = 0;
760 for (e =
first (h); 1; e = n)
784 ASSERT (free_count == elt_free_count);
785 ASSERT (free_size == elt_free_size);
787 ASSERT (total_size == vec_len (v));
793 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)
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
__clib_export void heap_dealloc(void *v, uword handle)
static uword get_free_elt(void *v, heap_elt_t *e, uword *bin_result)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#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).
description fragment has unexpected format
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)
sll srl srl sll sra u16x4 i
#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)
#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".