Notes on .NET, C#, self-hosted LLMs, Android and whatever else I break on the way.
Written since 2012, migrated from WordPress to a few static files.
Who is writing this?
sequential collection of chars immutable max 2GB or about 1 billion characters reference type are interned - CLR saves memory by maintaining a table, called the “intern pool”, that contains a single reference to each unique literal string declared or created programmatically in your program. Further read:
https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-7.0 https://learn.microsoft.com/en-us/dotnet/api/system.string.intern?view=net-6.0#remarks
ref struct type can not be used as object field.
Further read:
`ref struct` types https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/ref-struct
added as part of C# 7.2. defined with ref struct StructName always on the stack never part of heap cannot be element of an array cannot be field type of reference type can’t implement interfaces can’t be boxed can’t be type argument can’t be captured by closure of lambda or local function can’t be used in async methods can’t be used in iterators Further read:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/ref-struct
Reference types:
passed via reference reside on the heap subject to GC inherits from System.Object Value types:
passed via value reside on the stack, CPU registers or the heap no subject to GC inherits from System.ValueType Further read:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/reference-types https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-types https://www.infoworld.com/article/3043992/a-deep-dive-value-and-reference-types-in-net.html
shared type system across all .net languages primitives data types library 5 kind of types: classes structures enumerations interfaces delegates Further read:
https://learn.microsoft.com/en-us/dotnet/standard/base-types/common-type-system
provides a pool of threads can be used to execute tasks post work items process asynchronous I/O process timers Further read:
https://learn.microsoft.com/en-us/dotnet/api/system.threading.threadpool?view=net-6.0
simplify process of adding parallelism and concurrency to application scales concurrency automatically data parallelism task based async programming data flow Further read:
https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl
In short:
it will not work because it requires boxing and boxing will create new object for reference in lock every time code is executed so lock statement will not prevent anything.
Further read:
https://intellitect.com/blog/locking-a-block-of-code-with-an-integer/
avoid doing AsyncOperation.Result parent method waits for Result while child method waits for parent thread to take control, after being done with async I/O both waits deadlock Further read:
https://medium.com/rubrikkgroup/understanding-async-avoiding-deadlocks-e41f8f2c6f5d https://stackoverflow.com/questions/15021304/an-async-await-example-that-causes-a-deadlock