1

Topic: New ref readonly in C# and IL

Here such 20 numbers  : class Type1 {//This parameter will have an attribute (in IL) of type ` IsReadOnly ` public void Method1 (ref readonly int param1) {throw null;}//This method return type will have an attribute (in IL) of type ` IsReadOnly ` public ref readonly int Method2 () {throw null;}} What for upper (input) it is clear, though can and not up to the end. And what for lower (return)?  If it is possible an example steams - as became earlier and as now it to prepare And what for it in IL is necessary, it was possible only si-sharpom to manage

2

Re: New ref readonly in C# and IL

Hello, VladCore, you wrote: VC> Here such 20 numbers  : VC> VC> class Type1 VC> {VC>//This parameter will have an attribute (in IL) of type ` IsReadOnly ` VC> public void Method1 (ref readonly int param1) {throw null;} VC>//This method return type will have an attribute (in IL) of type ` IsReadOnly ` VC> public ref readonly int Method2 () {throw null;} VC>} VC> VC> What for upper (input) it is clear, though can and not up to the end. I understand it how const int * I.e. impossibility () for the caused code to change value under the pointer. VC> and what for lower (return)?  it is equal behind the same, but on the contrary. This inconvenience for the caused code to change that returned the caused code. After all it could return the link to the quotients of entrails which it is undesirable to change. VC> If it is possible an example steams - as became earlier and as now it to prepare with int th not strongly interesting. Here ValueTuple <double, double, double> - can already show an overhead charge for superfluous copying on a stack. Instead the link guaranteeing an invariance, allows us to read directly from fields of a class without copyings. VC> and what for it in IL is necessary, it is possible was only si-sharpom manage C# can to provide an invariance in frames C#, and what if someone IL programs by C#? Then any warranties does not quit.

3

Re: New ref readonly in C# and IL

VC>> If it is possible an example steams - as became earlier and as now it to prepare S> with int th not strongly interesting. Here ValueTuple <double, double, double> - can already show an overhead charge for superfluous copying on a stack. Instead the link guaranteeing an invariance, allows us to read directly from fields of a class without copyings. But I then removed a word ref absolutely and left only readonly. And let the compiler (or jit) itself solves - in a specific case to copy, transfer under the link better, or generally to define that from all structure one field is used only and to transfer it. And with ref readonly any generic  will be optimal or not, in addition a heap of literary trash, and a collection with ref both without absolutely different and on implementation and on usage, and thus  nonoptimality in any situation. Alas, in a command there is no captain evidence so probably to protest late, and further this hedgehog will live with us. P.S. Also what means ? In 15.5 preview 2 it works? And that in 15.4 is not present the such.

4

Re: New ref readonly in C# and IL

Hello, hi_octane, you wrote: _> P.S. Also what means ? In 15.5 preview 2 it works? And that in 15.4 is not present the such. It is already possible to download a. net Framework. In studio 2017.5 only will be

5

Re: New ref readonly in C# and IL

Hello, hi_octane, you wrote: _> But I then removed a word ref absolutely and left only readonly. And let the compiler (or jit) itself solves - in a specific case to copy, transfer under the link better, or generally to define that from all structure one field is used only and to transfer it. Semantics different is impossible so. The array under the link to an element can be transferred. And jit about it not to understand. _> and with ref readonly any generic  will be optimal or not, in addition a heap of literary trash, and a collection with ref both without absolutely different and on implementation and on usage, and thus  nonoptimality in any situation. Alas, in a command there is no captain evidence so probably to protest late, and further this hedgehog will live with us. The good hedgehog, let lives. With it it is better, than with unsafe.

6

Re: New ref readonly in C# and IL

Hello, VladCore, you wrote: VC> Here such 20 numbers  : . In 4.7.1 the attribute left only not to potter with njuget-packages for support. All remaining was with fw2 All began with Span <T> - wrappers round the arbitrary area of storage with  and without the penalty on productivity, including for obtaining/change of values of the enveloped array (well, or not an array). Here also were useful ref return which instead of pair a getter/setter allow to receive analog ref byte x = span [1];//(pseudocode).ldelema array span_offset+1 here all is obvious To mutable-types, but, say, for lines is necessary ReadOblySpan. That was not ref char x = stringSpan [1]; x = ' X ';//oops sm Details here. P.S. Well and certainly, with great power comes to blow up also a new method all to devils, where without it P.P.S. Yes, syntax for parameters will be in char x, not ref readonly x.

7

Re: New ref readonly in C# and IL

Hello, hi_octane, you wrote: _> But I then removed a word ref absolutely and left only readonly. And let the compiler (or jit) itself solves Idea from a series "to remove class/struct/interface, let the compiler itself solves". Well, i.e. at all evidence implementation attempt in metal inevitably leads to a scene "an owl and " _> P.S. Also what means ? In 15.5 preview 2 it works? And that in 15.4 is not present the such. In c#7.2 will be.

8

Re: New ref readonly in C# and IL

Hello, VladCore, you wrote: VC> [cs] VC> class Type1 VC> {VC>//This parameter will have an attribute (in IL) of type ` IsReadOnly ` VC> public void Method1 (ref readonly int param1) {throw null;} What for it is necessary, just not a question. At me the question is easier, why readonly instead of const?

9

Re: New ref readonly in C# and IL

Hello, Sinix, you wrote: S> P.P.S. Yes, syntax for parameters will be in char x, not ref readonly x. That is now "char x" and "in char x" will be in essence different methods of parameter passing? The first method as though too "in" as a matter of fact.

10

Re: New ref readonly in C# and IL

Hello, hi_octane, you wrote: _> But I then removed a word ref absolutely and left only readonly. And let the compiler (or jit) itself solves - in a specific case to copy, transfer under the link better, or generally to define that from all structure one field is used only and to transfer it. And with ref readonly any generic  will be optimal or not, in addition a heap of literary trash, and a collection with ref both without absolutely different and on implementation and on usage, and thus  nonoptimality in any situation. Alas, in a command there is no captain evidence so probably to protest late, and further this hedgehog will live with us. They try   const T&. If to leave only readonly there really begin implementation-specific focuses (who copies, who gives a weak reference, etc.) . And so it is accurately told: to give the link to the data, but with access readonly. In this history behavior GC is more interesting to me. Whether he will consider it as a weak reference (throwing an exception at attempt  readonly-referens on already  object) or the similar link will prolong object lifetime, promoting  following generations?

11

Re: New ref readonly in C# and IL

Hello, Mr. Delphist, you wrote: MD> Hello, hi_octane, you wrote: MD> They try   const T&. If to leave only readonly there really begin implementation-specific focuses (who copies, who gives a weak reference, etc.). And so it is accurately told: to give the link to the data, but with access readonly. How it is a weak reference? MD> in this history behavior GC is more interesting to me. Whether he will consider it as a weak reference (throwing an exception at attempt  readonly-referens on already  object) or the similar link will prolong object lifetime, promoting  following generations? Since there are possibilities to do ref no field exist ref can only on call stack. Any problems with GC cannot theoretically be. If is ref on reference type, means there is also the strong link. To remove it GC should not in any way.

12

Re: New ref readonly in C# and IL

Hello, samius, you wrote: S> as it is a weak reference? https://msdn.microsoft.com/en-us/librar … kreference (v=vs.110).aspx Represents a weak reference, which references an object while still allowing that object to be reclaimed by garbage collection.

13

Re: New ref readonly in C# and IL

Hello, Mr. Delphist, you wrote: MD> Hello, samius, you wrote: S>> as it is a weak reference? MD> https://msdn.microsoft.com/en-us/librar … kreference (v=vs.110).aspx MD> MD> Represents a weak reference, which references an object while still allowing that object to be reclaimed by garbage collection. What communication with ref th, except three general letters?

14

Re: New ref readonly in C# and IL

S> semantics different Is impossible so. The array under the link to an element can be transferred. And jit about it not to understand. Something did not understand that it changes for readonly ref vs copying at which one more link to the same array will be created. It is possible an example?

15

Re: New ref readonly in C# and IL

Hello, samius, you wrote: S> Hello, Mr. Delphist, you wrote: MD>> Hello, samius, you wrote: S>>> as it is a weak reference? MD>> https://msdn.microsoft.com/en-us/librar … kreference (v=vs.110).aspx MD>> MD>> Represents a weak reference, which references an object while still allowing that object to be reclaimed by garbage collection. S> What communication with ref th, except three general letters? I.e. a question in, whether 100 % will be equivalent to implementation of these two methods: class Type1 {private int _myInt = 42;//This method return type will have an attribute (in IL) of type ` IsReadOnly ` public ref readonly int Method2 () {return ref this. _ myInt;} public WeakReference <int> OldSchoolMethod2 () {return new WeakReference <int> (this. _ myInt);} }... var t = new Type1 (); ref int x = t. Method2 (); whether//it will influence on GC? WeakReference <int> y = t. OldSchoolMethod2 ();//because it - should not (y. Target == null after garbage collection) If under a cowl at "return ref readonly" there will be weak references the behavior of both methods identical is clear that. If is not present - that an underwater rake is interesting.

16

Re: New ref readonly in C# and IL

Hello, Mr. Delphist, you wrote: MD> If under a cowl at "return ref readonly" there will be weak references Certainly not will be, . All idea (motivation) at this feature that, that it was possible effectively (that is without copying) to accept/return the big short-lived structures (significant types); without engaging  and  managed-references. With implementation through weak-references (on objects in managed heap) it  is necessary for nobody.

17

Re: New ref readonly in C# and IL

Hello, hi_octane, you wrote: S>> semantics different Is impossible so. The array under the link to an element can be transferred. And jit about it not to understand. _> Something did not understand that it changes for readonly ref vs copying at which one more link to the same array will be created. It is possible an example? I do not understand, what for  to create the reference to an array if it is offered to it to return the link to an array cell or a field. In that and sense that through the link it is possible to accept/return either that, or another in the uniform image directly in one method.

18

Re: New ref readonly in C# and IL

Hello, Mr. Delphist, you wrote: S>> What communication with ref th, except three general letters? MD> I.e. a question in, whether 100 % will be equivalent to implementation of these two methods: MD> If under a cowl at "return ref readonly" there will be weak references the behavior of both methods identical is clear that. If is not present - that an underwater rake is interesting. return ref is about the same as ref-parameter. Only ref-parameter is a method to transfer value under the link. And return ref - to return. Under a cowl there it is equal T& from a C ++. readonly = const the modifier on value.

19

Re: New ref readonly in C# and IL

Hello, AngeL B., you wrote: AB> That is now "char x" and "in char x" will be in essence different methods of parameter passing? AB> the first method as though too "in" as a matter of fact. . And "[In] char x" for  still. That it was not boring. With variants especially you will not clear up, since for us to a campaign wait also immutable types/variables (through two releases, not earlier). But can and change, if in variant is better offer.

20

Re: New ref readonly in C# and IL

Hello, AngeL B., you wrote: AB> What for it is necessary, just not a question. At me the question is easier, why readonly instead of const? const would mean that value never changes, what not the fact.

21

Re: New ref readonly in C# and IL

Hello, Sinix, you wrote: S> Ugu. And "[In] char x" for  still. That it was not boring. S> with variants especially you will not clear up, since for us to a campaign wait also immutable types/variables (through two releases, not earlier). S> But can and change, if in variant is better offer. The keyword const how I understand, fell a victim of a NIH-syndrome?

22

Re: New ref readonly in C# and IL

Hello, VladCore, you wrote: And it is pleasant to me: Since all regular instance methods of a struct can potentially mutate the instance or ref-expose this, an intermediate copy must be created, as already a case when receiver is a readonly field. From here That is at first we make readonly ref because we do not want to copy the big structures, and then we do a structure copy on each method call. Well if took from pluses constant links also constant methods too take.

23

Re: New ref readonly in C# and IL

S> I do not understand, what for  to create the reference to an array if it is offered to it to return the link to an array cell or a field. S> in that and sense that through the link it is possible to accept/return either that, or another in the uniform image directly in one method. All the same I do not understand in what a problem. It is possible all the same an example when the user will receive something unexpected? My idea in that that in C# instead of readonly ref appeared a construction "readonly T x", which for structures (and only for them), assigned jit' - to do a call through ref (if structure big), or as usual - through a copy on a stack. We admit on an example of operation Collection <T>.IndexOf (readonly T x) where T: struct For structures in size with the register - jit will create a copy - just as now. And for structures in weight in kilobyte - itself to put on a call ref as the parameter readonly for the user exchanges nothing, and performance benefits. And as now made ms - at a collection it is necessary to have two different methods IndexOf (T x) and IndexOf (readonly ref T x), and adding in structure pair of fields - it is necessary to sit down and think, whether the structure grew up enough to run under the project and to change bottlenecks all potentially on readonly ref manually.

24

Re: New ref readonly in C# and IL

J> That is at first we make readonly ref because we do not want to copy the big structures, and then we do a structure copy on each method call. Well if took from pluses constant links also constant methods too take. The more they do different readonly the the impression is stronger that anybody from authors does not have background in a C ++, but is in JavaScript, VB and other pythons would begin with const methods Is better, let even the most stupid method - supporting  type  [Pure]

25

Re: New ref readonly in C# and IL

Hello, koandrew, you wrote: K> the Keyword const how I understand, fell a victim of a NIH-syndrome? const for compile-time expressions like hope . Plus, would be strange same concept (an invariable field / a variable) two  to name. However, if there is a substantiation and examples, it is possible to try it on  to write, can and react.