Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Nov 11, 2022
1 parent 415f37b commit 3586fd9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
9 changes: 4 additions & 5 deletions docs/site/articles/concepts.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# How does it work?
Before I answer the question, I would like to raise another question: How does it work differently and more effective than the current `StringBuilder`?
Before I answer the question, I would like to raise another question: How does it work differently and more effectively than the current `StringBuilder`?

The basic idea is to use a `ref struct` which enforces that the `ValueStringBuilder` will life on the **stack** instead of the **heap**.
Furthermore we try to use advanced features like `Span<T>` and `ArrayPool` to reduce allocations even further. Because of the way C# / .NET is optimized for those types the `ValueStringBuilder` gains a lot of speed with low allocations.

With this approach some limitations arise. Head over to the [known limitation](xref:known_limitations) to know more.
The basic idea is to use a `ref struct` which enforces that the `ValueStringBuilder` will live on the **stack** instead of the **heap**.
Furthermore, we try to use advanced features like `Span<T>` and `ArrayPool` to reduce allocations even further. Because of the way C# / .NET is optimized for those types the `ValueStringBuilder` gains a lot of speed with low allocations.
With this approach, some limitations arise. Head over to the [known limitation](xref:known_limitations) to know more.

## Resources:
[Here](https://steven-giesel.com/blogPost/4cada9a7-c462-4133-ad7f-e8b671987896) is my detailed blog post about some of the implementation details.
8 changes: 2 additions & 6 deletions docs/site/articles/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ public static class Program
```

Prints:

> Hello dear World!
0.3

[Here](https://dotnetfiddle.net/wM5r0q) an interactive example where you can fiddle around with the library. The example is hosted on [https://dotnetfiddle.net/](https://dotnetfiddle.net/wM5r0q) and already has the `ValueStringBuilder` nuget package included in the latest version.
[Here](https://dotnetfiddle.net/wM5r0q) is an interactive example where you can fiddle around with the library. The example is hosted on [https://dotnetfiddle.net/](https://dotnetfiddle.net/wM5r0q) and already has the `ValueStringBuilder` nuget package included in the latest version.

## Helper methods
There are also very easy to use helper methods, which doesn't need a `ValueStringBuilder` instance:
There are also very easy-to-use helper methods, which doesn't need a `ValueStringBuilder` instance:
```csharp
using LinkDotNet.StringBuilder;

Expand Down
10 changes: 5 additions & 5 deletions docs/site/articles/known_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
uid: known_limitations
---
# Known Limitations
The base of the `ValueStringBuilder` is a `ref struct`. With that there are certain limitations, which might make it not a good fit for your needs.
The base of the `ValueStringBuilder` is a `ref struct`. With that, there are certain limitations, which might make it not a good fit for your needs.
* `ref struct`s can only live on the **stack** and therefore can not be a field for a **class** or a non **ref struct**.
* Therefore they can't be boxed to `ValueType` or `Object`.
* Can't be captured ny a lambda expression (aka closure).
* Can't be captured by a lambda expression (aka closure).
* Can't be used in `async` methods.
* Can't be used in methods which use the `yield` keyword
* Can't be used in methods that use the `yield`` keyword

If not off this applies to your use case, you are good to go. Using `ref struct` is a trade for performance and less allocations in contrast to its use cases.
If not off this applies to your use case, you are good to go. Using `ref struct` is a trade for performance and fewer allocations in contrast to its use cases.

`ValueStringBuilder` offers the possibility to "convert" it into a "regular" `System.Text.StringBuilder`. Check out the following extension method via the <xref:LinkDotNet.StringBuilder.ValueStringBuilderExtensions>.

Expand All @@ -25,4 +25,4 @@ var greeting = stringBuilder
.ToString();
```

This does not work with the `ValueStringBuilder`. The simple reason: `struct`s can't return `return ref this`. If we don't return the reference then new allocations are introduced and can also lead to potential bugs / issues. Therefore it is a conscious design decision not to allow fluent notation.
This does not work with the `ValueStringBuilder`. The simple reason: `struct`s can't return `return ref this`. If we don't return the reference then new allocations are introduced and can also lead to potential bugs/issues. Therefore it is a conscious design decision not to allow fluent notation.
12 changes: 9 additions & 3 deletions docs/site/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

# ValueStringBuilder: A fast and low allocation StringBuilder for .NET

**ValueStringBuilder** aims to be as fast as possible with a minimal amount of allocation memory. This documentation will show case you how to use the `ValueStringBuilder` as well as what are some limitations coming with it. If you have questions or feature requests just head over to the [GitHub](https://github.com/linkdotnet/StringBuilder) repository and file and issue.
**ValueStringBuilder** aims to be as fast as possible with a minimal amount of allocation memory. This documentation will showcase to you how to use the `ValueStringBuilder` as well as what are some limitations coming with it. If you have questions or feature requests just head over to the [GitHub](https://github.com/linkdotnet/StringBuilder) repository and file an issue.

The library makes heavily use of `Span<T>`, `stackalloc` and `ArrayPool`s to achieve the low allocations and fast performance.
The library makes heavy use of `Span<T>`, `stackalloc` and `ArrayPool`s to achieve low allocations and fast performance.

## Download
The package is hosted on [nuget.org]((https://www.nuget.org/packages/LinkDotNet.StringBuilder/)), so easily add the package reference:
> PM> Install-Package LinkDotNet.StringBuilder
Afterwards you can simply use it. It tries to mimic the API of the `StringBuilder` to a certain extend so for simpler cases you can exchange those two.
Afterwards, you can simply use it. It tries to mimic the API of the `StringBuilder` to a certain extent so for simpler cases you can exchange those two.


## Example usage
Expand All @@ -31,4 +31,10 @@ This will print
```
Hello World
2+2=4
```

There are also convenient helper methods like this:
```csharp
_ = ValueStringBuilder.Concat("Hello", " ", "World"); // "Hello World"
_ = ValueStringBuilder.Concat("Hello", 1, 2, 3, "!"); // "Hello123!"
```

0 comments on commit 3586fd9

Please sign in to comment.