💾 Archived View for gmi.noulin.net › markdown › dynamicArray_README.md captured on 2023-07-10 at 18:17:50.

View Raw

More Information

-=-=-=-=-=-=-

# Dynamic array

- prefix: __dArray__
- direct access to array elements like regular C arrays with __dArrayAt__: dArrayAt(&darray, 0).structMember = true;
- no realloc
- the size is increased by pushing elements with __dArrayPush__
- compile with gcc on linux
- x86

(an improved version of this dynamic array is included in libsheepy.h)

# Usage

Create a dynamic array type to define the element type:

dArrayT(myDynt, type);


Declare a variable dynamic array:

myDynt darray;


Initialize the array:

dArrayInit(&darray);

or

dArrayInitCount(&darray, 17);


Push elements, it increases the size of the array when needed:

dArrayPush(&darray, value);


Get and set values with __dArrayAt__:

// get

int a = dArrayAt(&darray, 0);

// set

dArrayAt(&darray, 1) = 3;


Free the dynamic array with:

dArrayFree(&darray);


# Example

See __main.c__.