[OT] Unity migrating parts of their engine from C++ into High Performace C# (HPC#)

rikki cattermole rikki at cattermole.co.nz
Tue Apr 3 05:24:02 UTC 2018


On 03/04/2018 11:01 AM, Meta wrote:
> On Monday, 2 April 2018 at 22:55:58 UTC, Meta wrote:
>> On Monday, 2 April 2018 at 20:19:17 UTC, rumbu wrote:
>>> On Monday, 2 April 2018 at 18:54:28 UTC, 12345swordy wrote:
>>>>>
>>>>> - Only structs are used, no classes;
>>>>> - .NET collections are replaced by native collections that manage 
>>>>> their own memory
>>>>> - No code that would trigger GC is allowed
>>>>> - Compiler is aware of Unity features and is able to explore SIMD, 
>>>>> by doing auto-vectorization, and transparently transform structs 
>>>>> fields into optimal representations
>>>
>>>
>>> The struct type in C# is more versatile than the D's equivalent, 
>>> mainly because of the fact that you can inherit interfaces. You can 
>>> have template constraints in D but this is not as user friendly as a 
>>> struct interface.
>>>
>>> So in C# you can write code like this:
>>>
>>> interface IRange<T>
>>> {
>>>    void popFront();
>>>    bool empty();
>>>    T front();
>>> }
>>>
>>> struct MyRange<T>: IRange<T>
>>> {
>>>   //implementation
>>> }
>>>
>>> void foo<T>(IRange<T> someRange)
>>> {
>>>    //do something with someRange even it's a struct
>>>    //this includes code completion and other IDE specific stuff.
>>> }
>>>
>>>
>>> In D, template constrains are not very clean and they not have IDE 
>>> support:
>>>
>>> void foo(T)(T someRange) if (isInputRange!T)
>>> {
>>>
>>> }
>>
>> Worth mentioning is that doing this necessarily causes the struct to 
>> be boxed. I would not be surprised if they ban structs inheriting from 
>> interfaces.
> 
> To clarify, the struct will be boxed when passing it to a function that 
> accepts an IFoo, or if you do `IFoo foo = someStruct` or the like.

Shame we don't have signatures, then we'd have similar functionality 
only better!

https://github.com/rikkimax/DIPs/blob/master/DIPs/DIP1xxx-RC.md


More information about the Digitalmars-d mailing list