Author name: Amit Kumar

Optimizing Garbage Collection in .NET with GC.TryStartNoGCRegion()

What is GC.TryStartNoGCRegion()? GC.TryStartNoGCRegion() is a method that attempts to prevent garbage collection from occurring during critical performance sections by pre-allocating enough memory to satisfy allocation requests. It’s designed for scenarios where you need predictable, low-latency performance and cannot tolerate GC pauses. The method reserves memory upfront and prevents collections until you call GC.EndNoGCRegion() or …

Optimizing Garbage Collection in .NET with GC.TryStartNoGCRegion() Read More »

Using Unsafe Code in C# for Faster Memory Operations

What is Unsafe Code? Unsafe code in C# allows you to work directly with pointers and unmanaged memory, bypassing .NET’s memory safety guarantees. It enables operations like pointer arithmetic, direct memory access, and calling unmanaged functions. While it sacrifices safety for performance, it’s essential for scenarios requiring maximum speed, interop with native code, or low-level …

Using Unsafe Code in C# for Faster Memory Operations Read More »

Writing High-Performance Async Code with IValueTaskSource

What is IValueTaskSource? IValueTaskSource<T> is an interface that allows you to create custom awaitable types that can be pooled and reused, avoiding allocations associated with Task<T> objects. It’s the foundation for ValueTask<T>, which is a discriminated union that can represent either a completed synchronous result or an asynchronous Task<T>. This is particularly useful for high-performance …

Writing High-Performance Async Code with IValueTaskSource Read More »

How to Optimize C# Code with ref Structs and readonly Structs

What are ref Structs and readonly Structs? ref structs are value types that can only exist on the stack and cannot be boxed, stored in fields of reference types, or used as generic type arguments. They’re designed for high-performance scenarios where you want to avoid heap allocations entirely. readonly structs are immutable value types where …

How to Optimize C# Code with ref Structs and readonly Structs Read More »

Using Span and Memory for High-Performance Data Processing

What is Span<T> and Memory<T>? Span<T> and Memory<T> are value types introduced in .NET Core 2.1 that provide type-safe and memory-safe representation of a contiguous region of arbitrary memory. They enable zero-copy slicing of arrays, strings, and other memory buffers without allocating new objects on the heap. Span<T> is a stack-only type (ref struct) that …

Using Span and Memory for High-Performance Data Processing Read More »

Scroll to Top