News for hackers. Stuff that matters.
Re:Strings and the CLR – A Special Relationship by matthewwarren on Wednesday June 01, 2016 @07:07AM (#11813456)
I've seen Jil/Sigil before, but not thought about it in this way.

Are you saying that you could exactly replicate a C# System.String using IL, or am I mis-understanding?

Re:Strings and the CLR – A Special Relationship by jsingleton on Wednesday June 01, 2016 @08:44AM (#11813893)
No, I wasn't suggesting that you could implement the same high-performance System.String in IL, especially considering the assembly language used. I was just saying that there are many other things that can't be done in C# but are possible in .NET, using other languages.

BTW there is a typo: "passed in my the calling code" should probably be "passed in by the calling code".

I wonder if the new C# 6 string interpolation also uses string builder like format does. e.g.

  $"Name = {name}, hours = {hours:hh}"
https://msdn.microsoft.com/en-us/library/Dn961160.aspx

This post seems to suggest it uses concatenation, which may be bad for performance in some situations due to the immutability.

https://weblogs.asp.net/bleroy/c-6-string-interpolation-is-n...

Re:Strings and the CLR – A Special Relationship by matthewwarren on Wednesday June 01, 2016 @09:08AM (#11814034)
I just did a quick test with Reflector and it looks like string interpolation is turned into String.Format(..) calls, which in turn will use StringBuilder. This makes sense as String.Format(..) understands all the string formatting placeholders.

> BTW there is a typo: "passed in my the calling code" should probably be "passed in by the calling code".

Thanks for spotting that, I'll fix it in a bit

Re:Strings and the CLR – A Special Relationship by zamalek on Wednesday June 01, 2016 @07:36AM (#11813561)
I'm not sure if you could replicate System.String, because the oddity is happening at the metadata level - apart from special cases like String, .Net types must be compile-time constant length (if I remember correctly).

However, at the instruction level you can do some pretty awesome stuff. This slice[1] library is able to verifiably and safely grab a slice of data out of any arbitrary structure by using a MSIL feature that was invented for C++/CLR. The call site[2] is not unsafe.

[1]: https://github.com/joeduffy/slice.net/blob/master/src/PtrUti... [2]: https://github.com/joeduffy/slice.net/blob/master/src/Slice....

Re:Strings and the CLR – A Special Relationship by matthewwarren on Wednesday June 01, 2016 @07:45AM (#11813603)
Yeah the slice stuff is pretty nice, it's actually now being developed on the CoreFX Labs[1], so it might eventually make it into the Core CLR.

[1]: https://github.com/dotnet/corefxlab/tree/master/src/System.S...

Re:Strings and the CLR – A Special Relationship by pjmlp on Wednesday June 01, 2016 @07:11AM (#11813477)
Given that IL needs to be expressive enough to represent C++/CLI, I would guess it is possible.
Re:Strings and the CLR – A Special Relationship by ygra on Wednesday June 01, 2016 @07:28AM (#11813531)
But C++/CLI results in a mixed-mode half-native, half-managed assembly. It doesn't compile down to only IL.
Re:Strings and the CLR – A Special Relationship by poizan42 on Wednesday June 01, 2016 @08:36AM (#11813848)
Not if you use the /clr:pure flag