https://github.com/jonasraoni/memory-block
A set of simple functions to manage the memory of a dynamic array with fixed size items and contiguous memory.
https://github.com/jonasraoni/memory-block
array block c dynamic dynamic-array list memory memory-management
Last synced: 3 months ago
JSON representation
A set of simple functions to manage the memory of a dynamic array with fixed size items and contiguous memory.
- Host: GitHub
- URL: https://github.com/jonasraoni/memory-block
- Owner: jonasraoni
- License: mit
- Created: 2017-10-22T22:27:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-22T22:28:45.000Z (over 7 years ago)
- Last Synced: 2025-01-25T14:43:11.270Z (5 months ago)
- Topics: array, block, c, dynamic, dynamic-array, list, memory, memory-management
- Language: C
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Memory Block
A set of simple functions to manage the memory of a dynamic array with fixed size items and contiguous memory.
The MemoryBlock structure contains 4 elements:
data: pointer to the real data
capacity: storage capacity
size: data size of each itemThe block grows according to the current capacity, when capacity is:
> 64: allocate extra space for "capacity / 4" items
> 8: allocate extra space for 16 items
< 9: allocate extra space for 4 itemsBeing a dynamic block of memory, do not hold pointers to its internal data for too long as it may be reallocated to another address whenever there's not enough contiguous memory to grow.
## How to use
The header [memory-block.h](memory-block.h) contains the documentation.
Also check the file [test.c](test.c), it contains some examples and expectations. To compile the test:
- gcc:gcc -lm memory-block.c test.c -o test
- g++:g++ memory-block.c test.c -o test