https://github.com/kadealicious/dynamic-c-array
Create dynamically-allocated arrays of any data type in the C language.
https://github.com/kadealicious/dynamic-c-array
c c-memory-management dynamic-array memcpy void-pointers
Last synced: about 1 month ago
JSON representation
Create dynamically-allocated arrays of any data type in the C language.
- Host: GitHub
- URL: https://github.com/kadealicious/dynamic-c-array
- Owner: kadealicious
- Created: 2023-08-25T02:09:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-14T08:13:46.000Z (almost 2 years ago)
- Last Synced: 2023-12-14T09:30:53.305Z (almost 2 years ago)
- Topics: c, c-memory-management, dynamic-array, memcpy, void-pointers
- Language: C
- Homepage:
- Size: 1.03 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dynamic Array Library
The Dynamic Array Library is a C library that provides a dynamic array data structure, allowing you to work with resizable arrays in your C projects. It offers simple and intuitive functions to manage dynamic arrays efficiently.
## Features
- Dynamically resizable array data structure.
- Efficient insertion, removal, and replacement of elements.
- Ability to access elements by index.
- Automatic memory management for dynamic resizing.
- Simple initialization and freeing of dynamic arrays.
## Getting Started
To use the Dynamic Array Library in your project, follow these steps:
1. **Clone the Repository:** Clone this repository to your local machine.
2. **Include the Library:** Copy the `dynamicarray.h` and `dynamicarray.c` files from the `src` directory into your project directory.
3. **Compile:** Compile with `make` command to get output on build directory.
4. **Use the Library:** Include the `dynamicarray.h` header in your source files where you want to use the library's functionality. See the library's functions and documentation to understand how to work with dynamic arrays.
## Usage Example
Here's a simple example of using the Dynamic Array Library to create a resizable array of integers:
```c
#include "dynamicarray.h"
int main() {
daArray intArray = {}; // Make sure to zero-initialize all daArray objects for consistent behavior.
daInit(&intArray, 10, sizeof(int), true); // Initialize with 10 elements, each sizeof(int) bytes.
int value = 42;
daPushBack(&intArray, &value);
int retrievedValue = *(int*)daGet(&intArray, 0);
printf("Retrieved value: %d\n", retrievedValue);
daFree(&intArray); // Free the dynamic array's memory.
return 0;
}
```
## Documentation
For detailed information about the library's functions, parameters, and usage, refer to the [header file](./src/da.h).
## Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please create a GitHub issue or submit a pull request.
---
Happy coding with the Dynamic Array Library! If you have any questions or feedback, don't hesitate to get in touch.