Lines Matching refs:array
38 static bool grow(array_t* array);
45 array_t* array = static_cast<array_t*>( in array_new() local
48 array->element_size = element_size; in array_new()
49 array->capacity = INTERNAL_ELEMENTS; in array_new()
50 array->data = array->internal_storage; in array_new()
51 return array; in array_new()
54 void array_free(array_t* array) { in array_free() argument
55 if (!array) return; in array_free()
57 if (array->data != array->internal_storage) free(array->data); in array_free()
59 osi_free(array); in array_free()
62 void* array_ptr(const array_t* array) { return array_at(array, 0); } in array_ptr() argument
64 void* array_at(const array_t* array, size_t index) { in array_at() argument
65 CHECK(array != NULL); in array_at()
66 CHECK(index < array->length); in array_at()
67 return array->data + (index * array->element_size); in array_at()
70 size_t array_length(const array_t* array) { in array_length() argument
71 CHECK(array != NULL); in array_length()
72 return array->length; in array_length()
75 bool array_append_value(array_t* array, uint32_t value) { in array_append_value() argument
76 return array_append_ptr(array, &value); in array_append_value()
79 bool array_append_ptr(array_t* array, void* data) { in array_append_ptr() argument
80 CHECK(array != NULL); in array_append_ptr()
83 if (array->length == array->capacity && !grow(array)) { in array_append_ptr()
87 __func__, array->capacity, array->element_size); in array_append_ptr()
91 ++array->length; in array_append_ptr()
92 memcpy(array_at(array, array->length - 1), data, array->element_size); in array_append_ptr()
96 static bool grow(array_t* array) { in grow() argument
97 const size_t new_capacity = array->capacity + (array->capacity / 2); in grow()
98 const bool is_moving = (array->data == array->internal_storage); in grow()
100 void* new_data = realloc(is_moving ? NULL : array->data, in grow()
101 new_capacity * array->element_size); in grow()
105 memcpy(new_data, array->internal_storage, in grow()
106 array->length * array->element_size); in grow()
108 array->data = static_cast<uint8_t*>(new_data); in grow()
109 array->capacity = new_capacity; in grow()