Skip to content

Instantly share code, notes, and snippets.

namespace Demo
{
public class CursedBuffer
{
private readonly object[] data;
private readonly Pointer pointer;
public CursedBuffer(int size)
{
data = new object[size];
@antiduh
antiduh / FiniteFieldShuffler.cs
Created June 6, 2018 06:27
A permutation generator built on the mathematics of finite fields
using System;
using System.Collections;
namespace FiniteFieldShuffle
{
/// <summary>
/// Program to demonstrate an algorithm that generates a permutation of the values 0 through some
/// maximum value using finite fields.
/// </summary>
public static class Program
@antiduh
antiduh / Benchmark.cs
Last active February 8, 2018 18:50
Fastest byte array merge for reddit, https://www.reddit.com/r/csharp/comments/7w09vc/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using System.Threading;
namespace MergeBenchmark
{
internal static class Program
{
@antiduh
antiduh / SharedEvent.cs
Created March 8, 2017 21:43
Work-in-progress cross-process events
using System;
using System.Collections.Generic;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
namespace EventTest
@antiduh
antiduh / UserMutex.cs
Created November 30, 2016 22:38
Educational demonstration of how to build a spinning mutex from simplier parts, in C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Test
{
@antiduh
antiduh / FastConcat.cs
Last active April 16, 2019 03:11
Concatenates a list of strings into a single string by performing exactly one allocation.
/// <summary>
/// Provides the ability to concatenate arrays of strings and arrays of character arrays into a
/// single string without performing intermediate copies of the strings/characters, nor the
/// arrays that contain them.
/// </summary>
/// <remarks>
/// Methods like `string.Concat( string[] )` make an intermediate copy of the array containing
/// the strings (but not the strings themselves). If you have a large array of strings, then
/// copying that array can represent a moderate amount of unnecessary work. For instance,
/// copying a 500k element array in a 64-bit process requires copying about 4 MB of memory.
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
namespace TestProject
{
/// <summary>
/// Simple program to manually validate an XML document against a schema.
/// </summary>