Skip to content

Commit 4f89a16

Browse files
authored
Merge pull request #1 from NotKeira/copilot/check-bugs-improve-codebase
Fix critical alignment bug in FreeListAllocator and add comprehensive documentation
2 parents 30c810c + a48a4f1 commit 4f89a16

12 files changed

Lines changed: 1009 additions & 23 deletions

.editorconfig

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# Top-most EditorConfig file
4+
root = true
5+
6+
# All files
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
# C++ files
14+
[*.{cpp,h,hpp,cc}]
15+
indent_style = space
16+
indent_size = 4
17+
18+
# CMake files
19+
[{CMakeLists.txt,*.cmake}]
20+
indent_style = space
21+
indent_size = 4
22+
23+
# Markdown files
24+
[*.md]
25+
indent_style = space
26+
indent_size = 2
27+
trim_trailing_whitespace = false
28+
29+
# YAML files
30+
[*.{yml,yaml}]
31+
indent_style = space
32+
indent_size = 2
33+
34+
# JSON files
35+
[*.json]
36+
indent_style = space
37+
indent_size = 2

CONTRIBUTING.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Contributing to fast-alloc
2+
3+
Thank you for your interest in contributing to fast-alloc! This document provides guidelines and information for contributors.
4+
5+
## Code of Conduct
6+
7+
- Be respectful and constructive in all interactions
8+
- Focus on what is best for the community and the project
9+
- Show empathy towards other community members
10+
11+
## How to Contribute
12+
13+
### Reporting Bugs
14+
15+
If you find a bug, please create an issue with:
16+
- A clear, descriptive title
17+
- Steps to reproduce the issue
18+
- Expected behavior vs actual behavior
19+
- Your environment (OS, compiler, version)
20+
- Minimal code example demonstrating the bug
21+
22+
### Suggesting Enhancements
23+
24+
Enhancement suggestions are welcome! Please include:
25+
- Clear description of the enhancement
26+
- Use cases and benefits
27+
- Potential implementation approach (if you have ideas)
28+
- Any trade-offs or considerations
29+
30+
### Pull Requests
31+
32+
1. **Fork and Branch**: Fork the repository and create a feature branch
33+
```bash
34+
git checkout -b feature/your-feature-name
35+
```
36+
37+
2. **Code Style**:
38+
- Follow existing code style and conventions
39+
- Use C++20 features appropriately
40+
- Keep functions focused and reasonably sized
41+
- Add comments for complex algorithms
42+
- Use descriptive variable names
43+
44+
3. **Testing**:
45+
- Add tests for new features
46+
- Ensure all existing tests pass
47+
- Test on multiple platforms if possible (Windows, Linux, macOS)
48+
- Run with sanitizers to catch memory issues:
49+
```bash
50+
# Address Sanitizer
51+
cmake -B build -DCMAKE_BUILD_TYPE=Debug \
52+
-DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer -g"
53+
cmake --build build
54+
ctest --test-dir build --output-on-failure
55+
56+
# Thread Sanitizer (for thread-safe allocators)
57+
cmake -B build -DCMAKE_BUILD_TYPE=Debug \
58+
-DCMAKE_CXX_FLAGS="-fsanitize=thread -g"
59+
cmake --build build
60+
TSAN_OPTIONS="second_deadlock_stack=1 suppressions=tsan.supp" \
61+
ctest --test-dir build --output-on-failure
62+
```
63+
64+
4. **Documentation**:
65+
- Update README.md if adding new features
66+
- Add Doxygen comments for public APIs
67+
- Update docs/architecture.md for architectural changes
68+
- Include usage examples for new allocators
69+
70+
5. **Commit Messages**:
71+
- Use clear, descriptive commit messages
72+
- Start with a verb in imperative mood (e.g., "Add", "Fix", "Update")
73+
- Keep the first line under 72 characters
74+
- Add detailed explanation in the commit body if needed
75+
76+
6. **Pull Request Process**:
77+
- Ensure CI passes (all tests, sanitizers)
78+
- Update documentation as needed
79+
- Reference any related issues
80+
- Wait for review and address feedback
81+
82+
## Development Setup
83+
84+
### Prerequisites
85+
86+
- C++20 compatible compiler (GCC 10+, Clang 10+, MSVC 2019+)
87+
- CMake 3.14 or higher
88+
- Git
89+
90+
### Building
91+
92+
```bash
93+
# Configure
94+
cmake -B build -DCMAKE_BUILD_TYPE=Release
95+
96+
# Build
97+
cmake --build build --config Release
98+
99+
# Run tests
100+
ctest --test-dir build --output-on-failure
101+
102+
# Run benchmarks
103+
./build/alloc_benchmarks
104+
```
105+
106+
### Project Structure
107+
108+
```
109+
fast-alloc/
110+
├── src/ # Source code
111+
│ ├── *_allocator.h/cpp # Allocator implementations
112+
├── tests/ # Unit tests (Catch2)
113+
├── benchmarks/ # Performance benchmarks (Google Benchmark)
114+
├── docs/ # Documentation
115+
└── .github/workflows/ # CI configuration
116+
```
117+
118+
## Code Guidelines
119+
120+
### Memory Safety
121+
122+
- Always validate pointers in debug builds using assertions
123+
- Use RAII for resource management
124+
- Avoid raw pointer arithmetic where alternatives exist
125+
- Test with sanitizers (ASan, TSan, UBSan)
126+
127+
### Performance
128+
129+
- Profile before optimizing
130+
- Benchmark any performance-related changes
131+
- Document performance characteristics
132+
- Consider cache locality and alignment
133+
134+
### Assertions
135+
136+
Use assertions for preconditions that should never fail in correct usage:
137+
```cpp
138+
assert(size > 0 && "Size must be positive");
139+
assert(memory_ && "Allocator not initialized");
140+
```
141+
142+
### Thread Safety
143+
144+
- Document thread-safety guarantees in headers
145+
- Use appropriate synchronization primitives
146+
- Test concurrent operations under ThreadSanitizer
147+
- Consider lock-free alternatives for hot paths
148+
149+
## Testing Guidelines
150+
151+
### Unit Tests
152+
153+
- Test one thing per test case
154+
- Use descriptive test names
155+
- Cover edge cases (nullptr, zero size, exhaustion)
156+
- Test move semantics for movable types
157+
- Verify alignment requirements
158+
159+
### Benchmark Tests
160+
161+
- Compare against standard allocation (malloc/new)
162+
- Test realistic usage patterns
163+
- Run multiple iterations to reduce variance
164+
- Document platform and compiler used
165+
166+
## Release Process
167+
168+
Maintainers will:
169+
1. Review and merge pull requests
170+
2. Update version numbers
171+
3. Create release notes
172+
4. Tag releases
173+
174+
## Questions?
175+
176+
Feel free to:
177+
- Open an issue for questions
178+
- Start a discussion for general topics
179+
- Contact the maintainer directly
180+
181+
## License
182+
183+
By contributing, you agree that your contributions will be licensed under the MIT License.

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ fast-alloc/
113113

114114
## Usage Examples
115115

116-
### Pool Allocator
116+
For comprehensive usage examples and patterns, see [docs/USAGE.md](docs/USAGE.md).
117+
118+
### Quick Start
119+
120+
#### Pool Allocator
117121

118122
```cpp
119123
#include "pool_allocator.h"
@@ -126,7 +130,7 @@ void* obj = pool.allocate();
126130
pool.deallocate(obj);
127131
```
128132
129-
### Thread-Safe Pool Allocator
133+
#### Thread-Safe Pool Allocator
130134
131135
```cpp
132136
#include "threadsafe_pool_allocator.h"
@@ -146,7 +150,7 @@ t1.join();
146150
t2.join();
147151
```
148152

149-
### Stack Allocator
153+
#### Stack Allocator
150154

151155
```cpp
152156
#include "stack_allocator.h"
@@ -162,7 +166,7 @@ void frame_update() {
162166
}
163167
```
164168
165-
### Free List Allocator
169+
#### Free List Allocator
166170
167171
```cpp
168172
#include "freelist_allocator.h"
@@ -198,6 +202,10 @@ Comprehensive test suite with Catch2:
198202
- Concurrent stress tests for thread-safe variants
199203
- CI with multiple sanitizers (ASan, TSan, UBSan)
200204

205+
## Contributing
206+
207+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
208+
201209
## Licence
202210

203211
MIT Licence - see [LICENSE](LICENSE) for details.

0 commit comments

Comments
 (0)