-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Comments
Sounds largely like a dupe of #126: Proposal: Fixed-size buffers enhancements |
any progress? |
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. |
An experiment on Stack Allocation of classes can be found here: Rafael Teixeira On Fri, Oct 16, 2015 at 9:43 AM, HaloFour notifications@github.com wrote:
|
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. |
(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
};
The text was updated successfully, but these errors were encountered: