Skip to content

Conversation

@tannergooding
Copy link
Member

This resolves #118897

Copilot AI review requested due to automatic review settings December 2, 2025 15:02
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 2, 2025
Copy link
Contributor

Copilot AI left a 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 adds support for aligned memory allocation in the AllocateTypeAssociatedMemory API by introducing a new overload that accepts an alignment parameter. The implementation covers all three runtime variants (CoreCLR, Mono, and NativeAOT) and includes test coverage for the new functionality.

Key Changes

  • Added new AllocateTypeAssociatedMemory(Type, int, int) overload with alignment parameter across all runtime implementations
  • Updated XML documentation for existing overload to match new style guidelines
  • Implemented validation to ensure alignment is a power of 2
  • Added comprehensive test cases for both valid and invalid argument scenarios

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/libraries/System.Runtime/ref/System.Runtime.cs Added public API signature for the new aligned allocation overload
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs CoreCLR managed implementation with QCall to native code
src/coreclr/vm/runtimehandles.h Added native function declaration for aligned allocation
src/coreclr/vm/runtimehandles.cpp CoreCLR native implementation using LoaderHeap::AllocAlignedMem
src/coreclr/vm/qcallentrypoints.cpp Registered new QCall entry point for aligned allocation
src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs Mono implementation using NativeMemory.AlignedAlloc
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.NativeAot.cs NativeAOT implementation using NativeMemory.AlignedAlloc
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs Added test coverage for both invalid and valid arguments

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices
See info in area-owners.md if you want to be subscribed.

@tannergooding tannergooding force-pushed the fix-118897 branch 4 times, most recently from c82f51d to 2bc401a Compare December 2, 2025 18:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tannergooding
Copy link
Member Author

Removed the note and added tests for a few key sizes from 1-256kb:

[InlineData(1)]
[InlineData(2)]
[InlineData(4)]
[InlineData(8)]      // .NET largest natural alignment
[InlineData(16)]     // V128, typical max_align_t
[InlineData(32)]     // V256
[InlineData(64)]     // V512, typical cache line size
[InlineData(128)]    // less typical cache line size
[InlineData(512)]    // historical disk sector size
[InlineData(4096)]   // typical disk sector and page size
[InlineData(16384)]  // less typical disk sector and page size
[InlineData(65536)]  // typical texture and buffer alignment for GPU
[InlineData(262144)] // typical non-temporal chunk alignment

@tannergooding tannergooding enabled auto-merge (squash) December 4, 2025 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: RuntimeHelpers.AllocateTypeAssociatedMemory overload with alignment

3 participants