Lines Matching refs:buf
47 util_dynarray_init(struct util_dynarray *buf)
49 memset(buf, 0, sizeof(*buf));
53 util_dynarray_fini(struct util_dynarray *buf)
55 if(buf->data)
57 FREE(buf->data);
58 util_dynarray_init(buf);
64 util_dynarray_resize(struct util_dynarray *buf, unsigned newsize)
67 if(newsize > buf->capacity)
69 unsigned newcap = buf->capacity << 1;
72 buf->data = REALLOC(buf->data, buf->capacity, newcap);
73 buf->capacity = newcap;
76 p = (char *)buf->data + buf->size;
77 buf->size = newsize;
82 util_dynarray_grow(struct util_dynarray *buf, int diff)
84 return util_dynarray_resize(buf, buf->size + diff);
88 util_dynarray_trim(struct util_dynarray *buf)
90 if (buf->size != buf->capacity) {
91 if (buf->size) {
92 buf->data = REALLOC(buf->data, buf->capacity, buf->size);
93 buf->capacity = buf->size;
96 FREE(buf->data);
97 buf->data = 0;
98 buf->capacity = 0;
103 #define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow((buf), sizeof(type)), &__v, sizeof(type));} while(0)
104 #define util_dynarray_top_ptr(buf, type) (type*)((char*)(buf)->data + (buf)->size - sizeof(type))
105 #define util_dynarray_top(buf, type) *util_dynarray_top_ptr(buf, type)
106 #define util_dynarray_pop_ptr(buf, type) (type*)((char*)(buf)->data + ((buf)->size -= sizeof(type)))
107 #define util_dynarray_pop(buf, type) *util_dynarray_pop_ptr(buf, type)
108 #define util_dynarray_contains(buf, type) ((buf)->size >= sizeof(type))
109 #define util_dynarray_element(buf, type, idx) ((type*)(buf)->data + (idx))
110 #define util_dynarray_begin(buf) ((buf)->data)
111 #define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, (buf)->size))