Closed networkfusion closed 2 years ago
@networkfusion Your test code is causing the problem. you have:
sbvariable.Append(testStr);
when it should be:
sbfixed.Append(testStr);
Also i think the constructor StringBuilder(256) is for initial size not fixed size.
😱 , not sure how I missed that... Thanks. I will retest...
Any update on this?
Happy to close, it works now (if not a copy and paste error originally!).
Actually, changed my mind on closing... lets make sure the unit tests cover fixed size first!
internal static void Main()
{
string testStr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Debug.WriteLine("Starting String Tests");
Debug.WriteLine("");
Debug.WriteLine("Just adding test string to debug, Writeline...");
Debug.WriteLine($"testStrAdd: {testStr}");
Debug.WriteLine("Complete! Should have shown: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Debug.WriteLine("");
Debug.WriteLine("Start SB Variable");
var sbvariable = new StringBuilder();
sbvariable.Append("testStr SB Variable Size: ");
sbvariable.Append(testStr);
Debug.WriteLine(sbvariable.ToString());
Debug.WriteLine("Complete! Should have shown: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Debug.WriteLine("");
Debug.WriteLine("Start SB Fixed");
var sbfixed = new StringBuilder(256);
sbfixed.Append("testStr SB Fixed Size: ");
sbfixed.Append(testStr);
Debug.WriteLine(sbfixed.ToString());
Debug.WriteLine("Complete! Should have shown: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Debug.WriteLine("");
Thread.Sleep(Timeout.Infinite);
}
Is it really fixed size capacity or is it like in .Net the allocation size of the first chunk but StringBuilder
will add additional memory if required ?
I know that the official documentation of Microsoft is confusing to this regard.
You can check the test on .NET 6 at https://dotnetfiddle.net/M9Tg1X
@oblaise I think it is both. The intial chunk size and max allocation. Really to check if you get an exception when you try to append more than max.
It is that yes, initial size and it will add as needed. For reference: https://github.com/nanoframework/System.Text/blob/main/nanoFramework.System.Text/Text/StringBuilder.cs
Questions: is there anything wrong with our implementation of it? Do we have any incompatibility with the full .NET implementation that we should fix or make it clear about it?
@josesimoes No my misunderstanding came from the description in the bug above.
Library/API/IoT binding
System.Text
Visual Studio version
VS2022
.NET nanoFramework extension version
latest
Target name(s)
OrgPalThree
Firmware version
1.7.4.92
Device capabilities
Description
When using a fixed capacity, StringBuilder does not output. e.g.
StringBuilder(256);
How to reproduce
Run the sample program.
Expected behaviour
The
testStr SB Fixed Size:
should also contain0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
Screenshots
Sample project or code
Aditional information
Looking at the StringBuilder Tests, they only cover the empty constructer.