dynamicArray

general purpose dynamic array for one element type
git clone https://noulin.net/git/dynamicArray.git
Log | Files | Refs | README | LICENSE

README.md (898B)


      1 # Dynamic array
      2 
      3 - prefix: __dArray__
      4 - direct access to array elements like regular C arrays with __dArrayAt__: dArrayAt(&darray, 0).structMember = true;
      5 - no realloc
      6 - the size is increased by pushing elements with __dArrayPush__
      7 - compile with gcc on linux
      8 - x86
      9 
     10 (an improved version of this dynamic array is included in libsheepy.h)
     11 
     12 # Usage
     13 
     14 Create a dynamic array type to define the element type:
     15 ```
     16 dArrayT(myDynt, type);
     17 ```
     18 
     19 Declare a variable dynamic array:
     20 ```
     21 myDynt darray;
     22 ```
     23 
     24 Initialize the array:
     25 ```
     26 dArrayInit(&darray);
     27 or
     28 dArrayInitCount(&darray, 17);
     29 ```
     30 
     31 Push elements, it increases the size of the array when needed:
     32 ```
     33 dArrayPush(&darray, value);
     34 ```
     35 
     36 Get and set values with __dArrayAt__:
     37 ```
     38 // get
     39 int a                = dArrayAt(&darray, 0);
     40 
     41 // set
     42 dArrayAt(&darray, 1) = 3;
     43 ```
     44 
     45 Free the dynamic array with:
     46 ```
     47 dArrayFree(&darray);
     48 ```
     49 
     50 # Example
     51 
     52 See __main.c__.