[fpc-pascal] C# stackalloc

Michael Van Canneyt michael at freepascal.org
Sat Jun 2 08:44:04 CEST 2018



On Sat, 2 Jun 2018, Ryan Joseph wrote:

> As a sanity check for myself if you remember a while ago I posted about an idea for “stack aliases” to override the memory allocation for classes. No one really liked the idea and lots of potential safety concerns were raised (fair criticisms).
>
> By random chance today I came upon this feature of C# which basically does the same thing I was suggesting, as a way to override the default functionality of C# to allocate everything on the heap and garbage collect later. The reason stated for the feature is because it’s an optimization over the default heap-only allocation enforced for arrays.
>
> So it looks like my idea wasn’t that crazy after all. ;) Granted C# needs this feature more than FPC does because C# amazingly can’t allocate arrays on the stack otherwise (now that’s crazy!) but never the less the inclusion of “stackalloc” in C# gives the idea some credibility for FPC.
>
> https://www.c-sharpcorner.com/uploadfile/GemingLeader/creating-a-stack-based-array/



2 remarks:
1. It's only for arrays
2. It's for fixed-length arrays

So you can do this in FPC today.

Thirdly, you have objects which can be allocated on the stack, or advanced
records.

Plenty of choice for you.

Michael.


More information about the fpc-pascal mailing list