1,521 karma · joined May 25, 2012 (14y ago) · 286 submissions
comment 2y ago · link · parent
Over the years C# has been implementing these features too, which is good, but they have been implementing them in incompatible ways, which isn't very good. Since the investment in F# has been much smaller than in C#, it hasn't been innovating as fast as C# and has been left behind in some ways.
But it is still a great language and remains broadly compatible with the ecosystem and can deliver equal performance to C# with far less boiler plate
comment 2y ago · link · parent
I forgot that there is built in support for this model using the MemoryManager<T> class [0]. A memory manager is an abstract class that represents a block of other memory, including possibly unmanaged memory. It implements IDisposable already so you can just plug into this.
The Memory<T> struct can optionally internally point to a MemoryManager instance allowing you to plug your perfered style of allocation and freeing of memory into parts of the framework.
There is a little irony that a MemoryManager<T> is itself a class and therefore managed on the gc-heap, but you can defeat this by using ObjectPool<T> to recycle those instances to keep allocation count steady state and not trigger the GC.
I have used this before (in the toy database i mentioned earlier) to allocate aligned blocks of unmanaged memory.
[0] https://learn.microsoft.com/en-us/dotnet/api/system.buffers....
comment 2y ago · link · parent
Yes and no. Yes, almost all of the standard library collection are allocation heavy and it is still the dominate pattern in C#, so if you want to avoid the GC you need to avoid these and resort to building your own primitives based on Memory/Span. Which sucks.
However, you can use interfaces in a no GC world since you can constrain those interfaces to be structs or ref-structs and the compiler will enforce rules that prevent them from being boxed onto the GC heap.
Also of recent note, the JIT can now automagically convert simple gc-heap allocations into stack allocations if it can trivially prove they don't escape the stack context.
> It would be better if the GC can be turned off with a switch and just add a delete operator to manually free memory.
It is a little know fact that you can actually swap out the GC of the runtime. So you could plug in a null implementation that never collects (at your own peril...)
As for a delete operator, you can just roll your own struct based allocation framework that uses IDisposable to reclaim memory. But then you need to deal with all the traditional bugs like use-after-free and double-free and the like.
For me, I think low-gc is the happy medium. Avoid the heap in 99% of cases but let the GC keep things air tight
comment 2y ago · link · parent
comment 2y ago · link · parent
The test then becomes something like
Check.Sample(
Gen.Bool, Gen.Bool, Gen.Bool
(loggedIn, hasGreenHair, likesBananas) => {
var anyTrue = loggedIn | hasGreenHair | likesBananas;//the property to test
var messagePrinted = formatMessage(loggedIn, hasGreenHair, likesBananas);
Assert.Equal(anyTrue, messagePrinted);
}
);
This is obviously overkill for a test space of cardinality 8. But for complex cases this can provide better coverage of unexpected interactions than just stabbing a few positive and negative results.Another approach for this test would be to use a metamorphic property (also possible with CsCheck). You basically come up with a rule that says something like, "if a user is logged in, then it should not matter if they have green hair or if they are like bananas". Then just let the framework search for falsifiable cases.
A real-world example of this was when I designed a scheduling system that would compile a set of abstract rules down to concrete events. I used metamorphic testing to look for cases where "If I add a new rule to a calendar, the total observable complexity of the calendar should be greater than or equal to before" (the equal case is if the new rule was equivalent to an existing rule. This allowed me to ensure that the internal complexity wasn't dropping observable details.
74.
Microsoft Orleans v8.2.0(github.com ↗)
2 points · by algorithmsRcool · 2y ago · discuss
75.
Introduction to Vectorization with Vector128 and Vector256(github.com ↗)
2 points · by algorithmsRcool · 2y ago · discuss
76.
CsCheck: Random Testing Library for C#(github.com ↗)
1 points · by algorithmsRcool · 2y ago · discuss
comment 2y ago · link · parent
See: - https://github.com/AnthonyLloyd/CsCheck?tab=readme-ov-file#m... - https://github.com/AnthonyLloyd/CsCheck?tab=readme-ov-file#c...
79.
What's New in C# 13(learn.microsoft.com ↗)
13 points · by algorithmsRcool · 2y ago · 2 comments
comment 2y ago · link · parent
Shameless plug: I just wrote a beginner's introduction to Dafny a few days ago.
https://www.linkedin.com/pulse/getting-started-dafny-your-fi...
82.
Hysteresis effect on threadpool hill-climbing(github.com ↗)
2 points · by algorithmsRcool · 5y ago · discuss
comment 5y ago · link · parent
I dispute this. Yes, the normal spreadsheet view of excel will buckle under 1M rows, but excel has another feature called "Power Pivot" that is backed by an embedded database and scales into the high millions at least.
I've personally used excel on a dataset of 18M rows and PowerPivot handled it just fine.
[0] https://support.office.com/client/Data-Model-specification-a...
[1] https://support.office.com/client/power-pivot-powerful-data-...
comment 6y ago · link · parent
[1] https://support.office.com/client/power-pivot-powerful-data-...
[2] https://support.office.com/client/Data-Model-specification-a...