-
Notifications
You must be signed in to change notification settings - Fork 21
[0.7] [MOD-7297] Replace Variable Length Array on stack with heap allocation #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces variable length arrays (VLAs) on the stack with heap allocation to improve memory safety and portability. The change removes the use of stack-allocated arrays with dynamic sizes, which are not supported in all C++ standards and can cause stack overflow issues with large data sizes.
- Replaces VLA declarations with
allocate_aligned_unique()
andallocate_unique()
calls - Introduces new allocator methods that return
std::unique_ptr
with custom deleters for automatic memory management - Adds
getAlignment()
method to the VecSimIndexAbstract API
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/VecSim/vec_sim_tiered_index.h | Replaces stack-allocated VLAs with heap allocation in wrapper methods |
src/VecSim/vec_sim_index.h | Replaces stack-allocated VLAs with heap allocation in abstract class wrapper methods |
src/VecSim/memory/vecsim_malloc.h | Adds new allocator methods for unique_ptr-based allocation with custom deleter |
src/VecSim/memory/vecsim_malloc.cpp | Implements the new allocator methods for unique_ptr-based allocation |
src/VecSim/algorithms/hnsw/hnsw_tiered.h | Replaces VLA blob copy with heap allocation in insert job execution |
src/VecSim/algorithms/hnsw/hnsw_serializer.h | Replaces VLAs with heap allocation in graph restoration methods |
src/VecSim/algorithms/hnsw/hnsw.h | Replaces VLA for element graph data with heap allocation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
||
private: | ||
// Retrive the original requested allocation size. Required for remalloc. | ||
// Retrieve the original requested allocation size. Required for remalloc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The word 'remalloc' should be 'realloc' to match the standard C library function name.
// Retrieve the original requested allocation size. Required for remalloc. | |
// Retrieve the original requested allocation size. Required for realloc. |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remalloc is cute
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 0.7 #761 +/- ##
==========================================
+ Coverage 95.64% 95.70% +0.06%
==========================================
Files 69 69
Lines 4221 4238 +17
==========================================
+ Hits 4037 4056 +19
+ Misses 184 182 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
(late) backport of #505 to 0.7.
+
add getAlignment() to VecSimIndexAbstract API