132 _vec_len (h->
elts)--;
271 uword b, fb, f_size, f_index;
289 if ((s = f_size - size) >= 0)
362 void * _heap_alloc (
void * v,
366 uword * offset_return,
367 uword * handle_return)
369 uword offset = 0, align_size;
385 align_size = size + align - 1;
398 if (max_len && offset + align_size > max_len)
405 (offset + align_size) * elt_bytes,
409 _vec_len (v) += align_size;
431 uword new_offset, old_offset;
434 new_offset = (old_offset + align - 1) &~ (align - 1);
436 e_index = e - h->
elts;
439 if (new_offset > old_offset)
442 before_e->
offset = old_offset;
447 if (new_offset + size < old_offset + align_size)
455 e = h->
elts + e_index;
469 *offset_return = e->
offset;
470 *handle_return = e - h->
elts;
474 *offset_return = *handle_return = ~0;
495 e = h->
elts + handle;
506 uword total_size,
i, b, tb, ti, i_last, g_offset;
517 for (i = 0, e = e0; 1; e =
heap_next (e), i++)
542 g.index = g.bin_index = 0;
543 for (i = 0; i <= i_last; i++)
563 for (i = 0; i <= i_last; i++)
564 if (g.index != f[i].index)
585 void * _heap_free (
void * v)
613 bytes =
sizeof (h[0]);
639 for (j = 0; j < n/2; j++)
648 for (j = 0; j < n/2; j++)
656 s =
format (s,
"index %4d, free\n", e - h->
elts);
660 s =
format (s,
"index %4d, used\n", e - h->
elts);
671 void * v = va_arg (*va,
void *);
676 memset (&zero, 0,
sizeof (zero));
685 s =
format (s,
"heap %p, %6d objects, size %.1fk + overhead %.1fk\n",
686 v, h->
used_count, elt_bytes / 1024, (overhead_bytes - elt_bytes) / 1024);
702 uword used_count, total_size;
703 uword free_count, free_size;
711 free_size = free_count = 0;
726 uword elt_free_size, elt_free_count;
728 used_count = total_size = elt_free_size = elt_free_count = 0;
729 for (e =
first (h); 1; e = n)
752 ASSERT (free_count == elt_free_count);
753 ASSERT (free_size == elt_free_size);
755 ASSERT (total_size == vec_len (v));
761 for (i = o = 0; 1; i++)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
always_inline uword max_pow2(uword x)
static heap_elt_t * search_free_list(void *v, uword size)
sll srl srl sll sra u16x4 i
always_inline void set_free_elt(void *v, heap_elt_t *e, uword fi)
always_inline uword clib_bitmap_count_set_bits(uword *ai)
static void elt_delete(heap_header_t *h, heap_elt_t *e)
always_inline uword size_to_bin(uword size)
#define HEAP_LOG2_SMALL_BINS
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
u8 * format_heap(u8 *s, va_list *va)
always_inline void elt_insert_before(heap_header_t *h, heap_elt_t *e, heap_elt_t *new)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
always_inline uword max_log2(uword x)
#define vec_bytes(v)
Number of data bytes in vector.
always_inline heap_elt_t * elt_at(heap_header_t *h, uword i)
always_inline uword heap_get_max_len(void *v)
always_inline heap_elt_t * heap_next(heap_elt_t *e)
always_inline uword heap_is_free(heap_elt_t *e)
always_inline heap_header_t * heap_header(void *v)
always_inline heap_elt_t * last(heap_header_t *h)
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
#define vec_end(v)
End (last data address) of vector.
always_inline uword heap_offset(heap_elt_t *e)
always_inline void remove_free_block(void *v, uword b, uword i)
always_inline heap_elt_t * first(heap_header_t *h)
static void dealloc_elt(void *v, heap_elt_t *e)
uword heap_bytes(void *v)
static void combine_free_blocks(void *v, heap_elt_t *e0, heap_elt_t *e1)
always_inline uword clib_bitmap_get(uword *ai, uword i)
#define vec_free(V)
Free vector's memory (no header).
always_inline uword get_free_elt(void *v, heap_elt_t *e, uword *bin_result)
#define vec_capacity(v, b)
Total number of bytes that can fit in vector with current allocation.
always_inline uword bin_to_size(uword bin)
void heap_validate(void *v)
always_inline heap_elt_t * heap_prev(heap_elt_t *e)
void heap_dealloc(void *v, uword handle)
#define clib_bitmap_free(v)
static u8 * debug_elt(u8 *s, void *v, word i, word n)
always_inline u32 * elt_data(void *v, heap_elt_t *e)
uword heap_len(void *v, word handle)
#define vec_elt(v, i)
Get vector value at index i.
#define HEAP_ELT_FREE_BIT
#define vec_free_h(V, H)
Free vector's memory (general version)
always_inline heap_elt_t * elt_new(heap_header_t *h)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
always_inline uword heap_elt_size(void *v, heap_elt_t *e)
always_inline void elt_insert_after(heap_header_t *h, heap_elt_t *e, heap_elt_t *new)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".