A dynamic array that holds pointers to objects.
More...
Go to the source code of this file.
|
void | array_assign (struct array *const o_arr, size_t const i_growby) |
| initialize arrary object More...
|
|
void | array_discharge (struct array *const io_arr) |
| release resources held by object. The routine will not release resources held by the object itself. More...
|
|
void * | array_pop (struct array *const io_arr) |
| remove an element from the end of the array. Ownership of the object is transferred to the caller. More...
|
|
int | array_push (struct array *const io_arr, void *io_object) |
| adds an element to the end of the array More...
|
|
void * | array_remove (struct array *const io_arr, size_t const i_index) |
| removes an element from the array Ownership of the object is transferred to the caller. More...
|
|
A dynamic array that holds pointers to objects.
char * textptr;
#define GROWBY 30
assign_array(&myarray, GROWBY);
#undef GROWBY
for (some loop construct)
{
textptr= input_get_text();
}
{
free(text_ptr);
}
◆ array_assign()
void array_assign |
( |
struct array *const |
o_arr, |
|
|
size_t const |
i_growby |
|
) |
| |
initialize arrary object
- Parameters
-
[out] | o_arr | object ot initialize |
[in] | i_growby | number of elements to growby (expand) when array is full |
- Returns
- none
Memory allocated to store objects is peformed in array_push.
◆ array_discharge()
void array_discharge |
( |
struct array *const |
io_arr | ) |
|
release resources held by object. The routine will not release resources held by the object itself.
- Parameters
-
[in,ou] | io_arr object to release |
- Returns
- none
struct mydata* ptr= (struct mydata*)malloc(sizeof(*ptr));
◆ array_pop()
void * array_pop |
( |
struct array *const |
io_arr | ) |
|
remove an element from the end of the array. Ownership of the object is transferred to the caller.
- Parameters
-
[in,out] | io_arr | object to remove an element |
- Returns
- 0 array is empty
-
!0 pointer to element
◆ array_push()
int array_push |
( |
struct array *const |
io_arr, |
|
|
void * |
io_object |
|
) |
| |
adds an element to the end of the array
- Parameters
-
[in,out] | io_arr | object to store element |
[in,out] | io_object | object to store |
- Returns
- 0 success object added
-
-1 error unable to add object
◆ array_remove()
void * array_remove |
( |
struct array *const |
io_arr, |
|
|
size_t const |
i_index |
|
) |
| |
removes an element from the array Ownership of the object is transferred to the caller.
- Parameters
-
[in,out] | io_arr | object to remove element from |
[in] | i_index | zero based slot containing element to remove |
- Returns
- 0 array is empty or out of bounds
-
!0 pointer to removed object