Skip to content

Instantly share code, notes, and snippets.

@mattwarren
mattwarren / UnsafeWithoutKeyword.cs
Created September 4, 2019 20:52 — forked from nguerrera/UnsafeWithoutKeyword.cs
Absence of 'unsafe' C# keyword/switch does not guarantee type or memory safety.
/*
The absence of the C# unsafe keyword and switch does not guarantee code
is type or memory safe. It merely prevents the use of pointer types and
fixed size buffers.
The only thing that can guarantee type and memory safety is
verification and CAS/transparency enforcement.
In particular, the absence of unsafe C# blocks does NOT:
@mattwarren
mattwarren / on-tail-recursion.md
Created July 4, 2018 10:36 — forked from mrange/on-tail-recursion.md
On the topic of tail calls in .NET

On the topic of tail calls in .NET

Let's say you have implemented a small data pipeline library to replace LINQ.

module TrivialStream =
  type Receiver<'T> = 'T            -> unit
  type Stream<'T>   = Receiver<'T>  -> unit

  module Details =
@mattwarren
mattwarren / ValueLinqBenchmarks.cs
Created June 15, 2018 08:47 — forked from benaadams/ValueLinqBenchmarks.cs
Value Linq Benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
@mattwarren
mattwarren / veh_hook.cpp
Created January 5, 2018 10:24 — forked from ReubenBond/veh_hook.cpp
INT3 Vectored Exception Handler hooking
/**
veh_hook Vectored Exception Handler hooking library
Version: 24-March-2008
**/
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include "veh_hook.h"
static veh_list_t* list = NULL;
@mattwarren
mattwarren / BenchLinearVsBinary.cs
Created November 2, 2016 10:55 — forked from xoofx/BenchLinearVsBinary.cs
Performance between a linear and binary search on a small ordered set
/*
Q: At which size is it preferrable to use binary search over a simple linear search for a small ordered set?
R: Under 5 elements, linear search is slightly faster (from 200% to 10% faster)
But in practice, not sure a switch case to select the best method is really worth it
Unless main usecase is having most of the time only 1-2 elements (so it could be optimized manually without a loop and switch to binary otherwise)
At 3-4 elements, linear is only 10-5% faster
Relative performance between linear and binary search:
size x86 x64
[Config(typeof(Config))]
public class ContinueWithAllocations
{
private class Config : ManualConfig
{
public Config()
{
Add(new MemoryDiagnoser());
}
}
@mattwarren
mattwarren / clrmd-sdd-demo.cs
Created May 23, 2016 20:30 — forked from goldshtn/clrmd-sdd-demo.cs
CLRMD demo shown at SDD 2016
using Microsoft.Diagnostics.Runtime;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SDDTriage
{