[C++] MemoryPool::Allocate returns an error when the user provides small values for alignment
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 91
Description
### Describe the enhancement requested
The various allocators have minimum requirements for what can be passed to their "allocate aligned" utility.
For example, `posix_memalign` states:
> The address of the allocated memory will be a multiple of alignment, which must be a power of two and a multiple of sizeof(void *)
First, we should probably do our own check that alignment is a power of 2 and reject it with a clear error message. We should also add this requirement to the MemoryPool::Allocate method's documentation.
Second, if the user passes in a value that is a power of two, but is too small for the underlying allocator, then we should silently raise it to the first valid power of two. For example, if the user provides 4 then we should just raise that to 8. Any pointer that is 8-byte aligned is also 4-byte aligned so we fulfilled the user's request. This means that users don't have to know the details of the underlying allocator.
### Component(s)
C++
Contributor guide
Research direction
Start by locating the C++ MemoryPool::Allocate entry point and its documentation, then trace the aligned-allocation path for allocator minimum requirements. Confirm how invalid non-power-of-two values should be rejected and how smaller valid values should be handled. Done means the documented requirements and requested behavior are covered by relevant allocator tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, performance
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100