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

Please allow class contain memory of other class or fixed size array #2097

Closed
ygc369 opened this issue Apr 18, 2015 · 7 comments
Closed

Please allow class contain memory of other class or fixed size array #2097

ygc369 opened this issue Apr 18, 2015 · 7 comments

Comments

@ygc369
Copy link

ygc369 commented Apr 18, 2015

(I have proposed this idea in coreclr repository, but they say I should propose it here. You can see: https://github.com/dotnet/coreclr/issues/735#issuecomment-94121406)
Please allow class contain memory of other class or fixed size array. Thus, total object number can be less, and GC pressure can be lower, even accessing class fields can be faster because they can be directly located by accessing memory only once, not twice or more.
The class or array included in other class would act as struct, and can't be referenced.
For example, CLR should allow users to define class like this:
class A
{
class B { int x; char c; };
struct B b; // for example, use keyword "struct" to force class B to act as struct
B b0; // a reference to class B
B b1[10]; // reference array, the array itself is stored in class A, but b1[0]~b1[9] are only reference
struct B b2[10]; //b2[0]~b2[9] are not reference, they store all fields of class B
B[] b3; //a reference to a referencearray
struct B[] b4; //a reference to an array which stores values directly
int y[20]; //instead of "unsafe fixed int y[20]", when access "y", the index should be checked, so there is no necessary to use the keyword "unsafe"
int[] z; //normal array
};

@ygc369
Copy link
Author

ygc369 commented Apr 18, 2015

mem

@HaloFour
Copy link

Sounds largely like a dupe of #126: Proposal: Fixed-size buffers enhancements

@ygc369
Copy link
Author

ygc369 commented Oct 16, 2015

any progress?

@ygc369
Copy link
Author

ygc369 commented Oct 16, 2015

@HaloFour
Not same as #126, this one is more ambitious.
C# language should have the ability to use class as struct or use struct as class.

@HaloFour
Copy link

@ygc369

I'm not aware of any CLR functionality that would allow you to allocate a normal class on the stack or within the memory of another class. C++/CLI fakes it by still allocating the classes on the heap and using copy constructors.

@monoman
Copy link

monoman commented Oct 16, 2015

An experiment on Stack Allocation of classes can be found here:
http://xoofx.com/blog/2015/10/08/stackalloc-for-class-with-roslyn-and-coreclr/

Rafael Teixeira
O..:.)oooo

On Fri, Oct 16, 2015 at 9:43 AM, HaloFour notifications@github.com wrote:

@ygc369 https://github.com/ygc369

I'm not aware of any CLR functionality that would allow you to allocate a
normal class on the stack or within the memory of another class. C++/CLI
fakes it by still allocating the classes on the heap and using copy
constructors.


Reply to this email directly or view it on GitHub
#2097 (comment).

@gafter
Copy link
Member

gafter commented Mar 20, 2017

We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages.

@gafter gafter closed this as completed Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants