Thursday, December 31, 2020

Gem in C# - Span

System.Span<T> is a value type representing a continuous memory region for a collection of value type objects. It works like an array of value type <T>. Span<T> is a ref struct. Ref struct can only exist in stack and can't be the fields. Span can be used to access heap, stack, and unmanaged memory.

  • Supports type check by compiler
  • Boundary check at runtime
  • Indexer and Enumerator

Why should developers care?

  • Avoid overhead of allocation
  • Avoid overhead of memory copy
  • Avoid overhead of garbage collection 

What real-world problems can Span<T> solve?

  • Iterating a collection of value types (simple types, struct, enum), such as byte[], involves memory copy because value type by default is pass-by-value.
  • String.Substring could be used to carve out just the piece that’s interesting to them, but that’s a relatively expensive operation, involving a string allocation,  memory copy, and garbage collection. 
  • Coding with raw pointer is dangerous because it has no strong-type and boundary-check in runtime.  
  • Same logic has to be implemented for different memories, such as heap, stack, and native code (unmanaged memory, interop).

Final words

Microsoft Search Engine Bing is written in .NET Core. The performance of Bing has improved by 34% after using Span<T>.

Span<T> is one of the gems in C#.

Enjoy!

Best Features for C# Language (2.0-9.0)

 C# 2.0 language: 

Generics, nullable types, anonymous methods etc.

C# 3.0 language: 

LINQ, extension methods, lambda expressions, var (implicit types), get/set shortcuts etc.

C# 4.0 language: 

dynamic (late binding), optional arguments, covariance and contravariance in collections etc. 

C# 5.0 language: 

async/await, Caller Info

C# 6.0 language: 

string interpolation, dictionary initializer, nameof, using static

c# 7.0 Language

Span, ref struct, in, out, 

C# 8.0 Language

Async Streaming, Patterns, indices and range

C# 9.0 Language

        record, Covariant return types, Lambda discard parameters



Sunday, December 27, 2020

Yadex Release v1.1 Published on GitHub




Yadex Retirement
 is an asset management desktop application to help you reach the goal of F.I.R.(E.) — Financial Independence, Retire (Early.)

     https://github.com/tonyjy/YadexRetirement 

  • Track your assets performance
  • Categorize your assets
  • Summarize your assets
  • Evaluate your retirement goal

Yadex Retirement runs on Windows only.

  • Asset total tracking year over year.
  • Asset details tracking year over year.
  • Asset add, update, and duplicate.

To run the executable, please unzip Yadex_v1.1.0_win10-x64_EXE.zip and run Yadex.Retirement.exe

     Yadex_v1.1.0_win10-x64_EXE.zip

Author: Tony Jiang

Released Date: 12/26/2020



Be A Developer That Uses AI

Developers will not be replaced by AI, they'll be replaced by developers that use AI. Generative AI tools are revolutionizing the way de...