tStack
The name of this type is misleading, as it is not actually a stack, but an array (i.e. it allows random access by means of an index). |
Members
- void** data
-
Array of data pointers. Should be cast to actual type before use.
The data array is meant to contain pointers to the actual data, not the data itself. - int nmax
-
Number of items for which there is memory allocated.
- int n
-
Number of items currently in the "stack".
- int i
-
Internal iteration variable, used by the looping macros. Should never be touched.
A tStack is similar to a vector in C++, or slices in Go or Rust, in that the amount of memory allocated may be larger that required by its current contents require. |
Relevant functions
- tStack *stack_create()
-
Create an empty tStack with 0 elements and no memory allocated.
- tStack *stack_create_nmax(int nmax)
-
Create a tStack with 0 elements, but memory allocated for up to nmax elements.
- tStack *stack_create_n(int n)
-
Create a tStack with n elements, with all elements initialized to NULL.
- void stack_add(tStack *stack, void *item)
-
Add item to stack. If stack is too small to accomodate the new element, it will be reallocated to be larger (in steps of 64 elements).
- void stack_drop_index_unordered(tStack *stack, int i)
-
Remove item with index i from stack, and move last element into its place.
- void stack_free(tStack *stack)
-
Frees the memory allocated for stack. Also calls
free
on stack itself.