Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-06

C# stackalloc

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

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/

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Ryan Joseph
Ryan Joseph wrote 7 lines
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.

Reply by email

Ryan Joseph
to Michael Van Canneyt
Show quoted text 12 lines
On Jun 2, 2018, at 1:44 PM, Michael Van Canneyt wrote: 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.

yes indeed. It’s just interesting because “stackalloc” basically swaps the memory backend and there’s a precedent for such a thing happening and in a very popular language. The hacker in me wants to play around with that idea in FPC to see what emerges.

If management operators stick around there’s lots of potential to make advanced records a strong alternative. Best feature added to FPC is a while IMO so hopefully they survive the drama. :)

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Ryan Joseph
Ryan Joseph wrote 18 lines
> On Jun 2, 2018, at 1:44 PM, Michael Van Canneyt wrote: > > 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. yes indeed. It’s just interesting because “stackalloc” basically swaps the memory backend and there’s a precedent for such a thing happening and in a very popular language. The hacker in me wants to play around with that idea in FPC to see what emerges. If management operators stick around there’s lots of potential to make advanced records a strong alternative. Best feature added to FPC is a while IMO so hopefully they survive the drama. :)

People have come and went. But the features have always remained. They may receive more or less TLC of course.

Personally, I don't understand the obsession with language features. If anything, I would make the language more simple. But this is just me swimming against the current.

Michael.

Reply by email

Ryan Joseph
to Michael Van Canneyt
On Jun 2, 2018, at 2:54 PM, Michael Van Canneyt wrote: Personally, I don't understand the obsession with language features. If anything, I would make the language more simple. But this is just me swimming against the current.

Ironically I totally agree but it’s so difficult to determine what is “necessary” and what isn’t. Sometimes it takes 10 years of real world implementation to realize something was a bad idea.

Were there people that argued against operator overloads and advanced records I wonder? Those I’m 100% certain were good ideas and really make my life better. I'm even suspect of generics even though I use them often. I don’t use dynamic arrays but others here seem really attached to them.

Even with all the language cruft at least FPC doesn’t force any of it on you like C# forces you to use classes for everything and denies you from allocating stuff on the stack. That’s where it crosses a very real line for me. You can still make procedural program and be totally oblivious to everything that happened in the last 20 years. :)

Regards,
Ryan Joseph

Reply by email

Unknown author
to Ryan Joseph: As a sanity check for myself if you remember a while ago I posted about an idea for…
Ryan Joseph wrote
So it looks like my idea wasn’t that crazy after all. ;)

just because more than one person comes up with the same or similar idea does not mean that it is not crazy or worse ;) ;) ;)

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list unless* *a signed and pre-paid contract is in effect with us.*

Reply by email