Skip to main content

Dynamic arrays

Dynamic arrays are a way to store multiple custom data contigues in memory.

Usage

This example shows, how to use the data structure, how to create it, how to interact with it and how to destroy it.

#include <Containers/DynamicArray.h>

typedef struct CustomData
{
void *some_member;
i64 some_value;
} CustomData;

void foo()
{
// Creation
CustomData *data = FAKE_DARRAY_CREATE(CustomData);

// Filling the data
for (u32 i = 0; i < 10; ++i)
{
CustomData current = {0};
current.some_member = 0;
current.some_value = 42;
FAKE_DARRAY_PUSH(data, current);
}

// Reading the data
u32 length = FAKE_DARRAY_LENGTH(data); // = 10.
for (u32 i = 0; i < length; ++i)
{
CustomData *current_data = &data[i];
current_data->some_member;
current_data->some_value;
}

// Destruction
FAKE_DARRAY_DESTROY(data);
data = 0;
}
note

If the member was allocated manually, then you also need to free the members manually.