core: Add Array template class to abstract a fixed-size contiguous buffer whose size is determined at runtime.#513
Merged
Conversation
kirkrodrigues
requested changes
Aug 17, 2024
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
kirkrodrigues
approved these changes
Aug 18, 2024
kirkrodrigues
left a comment
Member
There was a problem hiding this comment.
For the PR title, how about:
core: Add Array template class to abstract a fixed-size contiguous buffer whose size is determined at runtime.
Member
|
Workflow failure is unrelated and is being tracked in #519. |
Array template class for fix-sized continuous storage at run-time.Array template class to abstract a fixed-size contiguous buffer whose size is determined at runtime.
jackluo923
pushed a commit
to jackluo923/clp
that referenced
this pull request
Dec 4, 2024
…buffer whose size is determined at runtime. (y-scope#513)
4 tasks
junhaoliao
pushed a commit
to junhaoliao/clp
that referenced
this pull request
May 17, 2026
…buffer whose size is determined at runtime. (y-scope#513)
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.
Description
In the current CLP, we use unique pointers of C-style arrays across the code base whenever we need a fix-sized buffer. This violates
clang-tidysuggestions which advocate deprecating C-style arrays. However, existingstdcontainers have limitations to use.std::vector, it is hard to control the underlying storage. The storage size is controlled by its capacity but not the size. Also, the vector can't be made immutable to use the storage as a buffer to receive data (such as the use case inNetworkReader). This means there's no way to avoid reallocation/resizing by mistakes. Declaring a vector and using its underlyingdata()buffer will not provide any safety.std::array, the size must be given in the compile time.Therefore, we introduce our own implementation of arrays,
clp::Array, which is a fix-sized array where the size is determined during the run-time. We usestd::unique_ptrto manage the underlying buffer storage (which is allocated in the heap), and a member to keep track of the size to avoid out-of-bound access. This PR implements the basic features of our array, including methods for random access and iterators. At this stage, the underlying element of the array must be default initializable so that we don't have to implement the initializer list constructor yet.APIs of this class are designed to mirror
stdcontainers.Validation performed
stdalgorithms.