Add realloc and remove redundancies#33
Merged
pavel-kirienko merged 22 commits intomasterfrom Jan 21, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds o1heapReallocate functionality to enable efficient memory reallocation with constant-time complexity in most cases, addressing issue #21. The implementation includes comprehensive optimization of internal functions and removal of the trace functionality that was added in v2.2.
Changes:
- Adds
o1heapReallocate()API with multiple strategies: shrink-in-place, expand-forward, expand-backward, and alloc-copy-free fallback - Removes
log2Ceilfunction (optimization: reuseslog2Floorwhere quotients are powers of 2) - Optimizes
rebin/unbinby passing fragment sizes as parameters to avoid redundantfragGetSizecalls - Removes trace functionality (
O1HEAP_TRACE,o1heapTraceAllocate,o1heapTraceFree) - Adds comprehensive test coverage for all realloc scenarios including edge cases
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| o1heap/o1heap.c | Implements o1heapReallocate with 4 strategies; optimizes rebin/unbin; removes log2Ceil and trace; adds larger() helper |
| o1heap/o1heap.h | Documents new o1heapReallocate API; removes trace function declarations |
| tests/test_general.cpp | Adds 956 lines of comprehensive realloc tests; removes trace tests; reduces test memory/iterations |
| tests/test_api_exhaustive.cpp | Adds realloc edge case tests with realloc operations in random walk tests |
| tests/internal.hpp | Adds reallocate() wrapper method |
| tests/CMakeLists.txt | Fixes paths from CMAKE_SOURCE_DIR to CMAKE_CURRENT_SOURCE_DIR; removes trace test |
| tests/.clang-tidy | Disables -use-ranges and -signed-bitwise warnings |
| perftest/main.c | Refactors to compare o1heap vs malloc using abstraction layer |
| perftest/README.md | Adds benchmark results showing o1heap's performance advantages |
| README.md | Updates performance numbers; documents realloc addition; removes trace documentation |
| CMakeLists.txt | Adds top-level CMake file for project |
| AGENTS.md, CLAUDE.md | Adds AI agent instructions |
| .github/workflows/main.yml | Updates cmake to build from root directory |
Files not reviewed (1)
- .idea/dictionaries/project.xml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #21