BaseMax / my-c-array
Dynamic array implementation in C with a modular, folder-based structure.
README
my-c-array
Dynamic array implementation in C with a modular, folder-based structure.
๐ง Features
- ๐งฉ Modular Operations: Efficient functions for array append, prepend, resize, delete, and access.
- ๐ ๏ธ Custom Memory Management: Define custom free functions for array element deallocation.
- ๐ Expandable: Easily extendable with additional array-related functions.
- ๐ Cross-Platform: Build scripts for both Linux (bash or make) and Windows (batch).
- ๐ Organized Structure: Each module is in its own directory for easy maintenance.
- ๐ Static Library: Compiles into libmyarray.a for easy reuse in other projects.
- โ๏ธ C Standard: Written in pure C for maximum compatibility.
- ๐ Easy to Build: Simple setup for compiling and integrating into other projects.
๐๏ธ Suggested Directory Layout
my-c-array/
โโโ Makefile
โโโ build.sh
โโโ build.bat
โโโ libmyarray.a (after build)
โโโ src/
โ โโโ array_append/
โ โ โโโ array_append.c
โ โ โโโ array_append.h
โ โโโ ...
๐ ๏ธ Build Instructions
Linux / macOS
chmod +x build.sh
./build.sh
Or using make:
make
Windows
build.bat
This will compile the source files under src/, place the object files in build/, and generate a static library libmyarray.a or an executable if you add a main.c.
๐ฆ Functions
- Modular directory layout
- Cross-platform build scripts (
.shand.bat) - Basic operations like:
array_createarray_appendarray_deletearray_getarray_resizearray_prependarray_size
๐ Example Header
Hereโs what the base array type looks like:
#ifndef _ARRAY_TYPE_H_
#define _ARRAY_TYPE_H_
#include <stddef.h> // for size_t
typedef void (*array_free_func_t)(void*);
typedef struct {
void** items; // actual data
size_t capacity; // total capacity
size_t size; // current number of elements
array_free_func_t freer; // custom free function (NULL means no-op)
} array_t;
#endif
๐ License
MIT License
ยฉ 2025 Max Base
