Skip to content

Instantly share code, notes, and snippets.

View marv7000's full-sized avatar
🦆

Marvin Friedrich marv7000

🦆
View GitHub Profile
@marv7000
marv7000 / perm_mode_str.h
Created May 5, 2024 22:40
[C23] Compile time constant file permission flags from a string
#pragma once
/*
* Scary abuse of the sizeof syntax so static_assert gets evaluated.
* If it passes, we don't want to modify the result though, so AND with 0.
* This is illegal in C++!
*/
#define MODE_ASSERT(x, m) sizeof(struct { static_assert(x, m); char _ghost; }) & 0
/*
@marv7000
marv7000 / Block.cs
Created July 25, 2023 00:11
Minimal wrapper around an unmanaged pointer as an array.
using System.Runtime.InteropServices;
namespace BlockImpl;
/// <summary>
/// Manages a sequential area of memory like <see cref="Span{T}"/>, but on the unmanaged heap.
/// When used on managed or stack memory, make sure to call <see cref="MarkMemoryAsFragile"/>.
/// </summary>
/// <typeparam name="T">Underlying type.</typeparam>
public unsafe class Block<T> : IDisposable where T : unmanaged