-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime.CompilerServiceshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors
Milestone
Description
Background and motivation
RuntimeHelpers.AllocateTypeAssociatedMemory is an API that's very useful for allocating private, permanent buffers for lookup tables and such.
It doesn't however provide a way to specify the alignment which makes the users that require it for correctness or performance have to manually ensure that via for example overallocating today.
As such, I propose that an overload that allows it to be specified would be added.
API Proposal
namespace System.Runtime.CompilerServices;
public static class RuntimeHelpers
{
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size, int alignment);
}API Usage
public static class SimdAlgorithm
{
public static readonly byte* SimdLookupTable = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(SimdAlgorithm), 4096, 64);
}Alternative Designs
The API could return void* instead and take parameters as nuint, I decided to match the existing overload for now though.
Risks
Matching IntPtr return might be problematic with the new unsafe guidelines.
ovska
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime.CompilerServiceshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors