Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Allow a non-fixed size array embedded in a class #210

Closed
ygc369 opened this issue Mar 1, 2017 · 3 comments
Closed

Proposal: Allow a non-fixed size array embedded in a class #210

ygc369 opened this issue Mar 1, 2017 · 3 comments

Comments

@ygc369
Copy link

ygc369 commented Mar 1, 2017

Related to #115 and dotnet/roslyn#6055
For example:

class A
{
    int a;
    object o[]; // not same as "object[] o;"
    public A(int a0)
    {   a=a0;  }
}
A aa=new(10) A(5); //aa.o.Length=10, aa.a=5
object o1=aa.o[9]=3; //ok, access to any elements of aa.o is ok
object[] o=aa.o; //compile error! aa.o is not a real array, it's embedded in aa, so it can't be referenced directly!

A class can only have at most one array with dynamic length, but can have more than one inline arrays with fixed length.
for example:

class A
{
    int a[10]; // fixed size
    int b[20]; //fixed size
    object c[]; //dynamic size
}
@Thaina
Copy link

Thaina commented Mar 1, 2017

You could use 3 grave accent to make code block

 > like this
 > ```C#
 > code
 > ```

@ig-sinicyn
Copy link

ig-sinicyn commented Mar 1, 2017

@ygc369
but why? You cannot save anything in terms of allocation size. You had to have an object header for the array or you will not able to pass it into another methods.

There's no gain in terms of memory locality as CLR allocates objects sequentially (this is simplified version, I know:) ).

There's no point to use embedded arrays for collection types as it's impossible to resize the embedded array without reallocating entire collection object.

And finally, there's no way to enable dynamic-sized embedded arrays for structs.

So, what's the point? 😕

The same relates to #212. There's stackalloc for locals and there will be Span / Memory for almost anything else.

What's missing? : )

@ygc369 ygc369 closed this as completed Mar 2, 2017
@jnm2
Copy link
Contributor

jnm2 commented Mar 2, 2017

@Thaina you can also use more than three backticks if what you're trying to show contains three backticks:

You can use 3 backticks to make a code block:

````markdown
```c#
code
```
````

Becomes:

You can use 3 backticks to make a code block:

```c#
code
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants