Dynarray.c
Data Structures | Functions
dynarray.h File Reference
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  array_info
 Saves stats about the array for memory handling. More...
 

Functions

void * construct_array (size_t capacity, size_t item_size)
 Creates a dynamic array. More...
 
array_infoget_array_info (void *array)
 Retrieves the array information of a given array. More...
 
void insert_at (void *array, void *item, int pos)
 Inserts an item in a specific slot, overwriting any existing item. More...
 
size_t array_length (void *array)
 Gets the length of the array. More...
 
void push_back (void *array, void *item)
 Pushes to the back of the array length. More...
 

Detailed Description

This header file defines the publically available functions

Function Documentation

◆ array_length()

size_t array_length ( void *  array)

Gets the length of the array.

Parameters
arrayA pointer to the array
Returns
The length of the array

◆ construct_array()

void* construct_array ( size_t  capacity,
size_t  item_size 
)

Creates a dynamic array.

Parameters
capacityThe initial number of available slots for the array
item_sizeThe size, in bytes, of the item that will be stored in this array
Returns
A pointer to the array

◆ get_array_info()

array_info* get_array_info ( void *  array)

Retrieves the array information of a given array.

Parameters
Arraya pointer to a dynamic array
Returns
A pointer to a array_info block

◆ insert_at()

void insert_at ( void *  array,
void *  item,
int  pos 
)

Inserts an item in a specific slot, overwriting any existing item.

Parameters
arrayA pointer to the array
itemThe item to be inserted
posThe, zero-indexed, position to place the item

◆ push_back()

void push_back ( void *  array,
void *  item 
)

Pushes to the back of the array length.

Parameters
arrayA pointer to the array
itemA pointer to the item to insert