Future of memory management in D

Rumbu rumbu at rumbu.ro
Thu Nov 18 15:14:07 UTC 2021


On Thursday, 18 November 2021 at 14:31:36 UTC, Nick Treleaven 
wrote:
> On Thursday, 18 November 2021 at 06:25:29 UTC, rumbu wrote:
>> Lol. Look, C# is not a garbage collected language:
>>
>> int* x = stackalloc int[100];
>> int* y = Marshal.AllocHGlobal(1000);
>> struct RC<T> where T: struct { ... }
>>
>> O course, metaprogramming makes things easier in D, but 
>> pretending that D is not a garbage collected language when you 
>> cannot join two arrays or throw an exception without digging  
>> outside the language for a replacement is absurd.
>
> @nogc unittest
> {
> 	import std.container.array;
> 	auto a = Array!int(1, 2);
> 	auto b = Array!int(3, 4);
> 	a ~= b;
> 	import std.algorithm;
> 	assert(a[].equal([1,2,3,4]));
>
> 	static const ex = new Exception("hi");
> 	throw ex;
> }

As I said, you are digging outside the language spec with Array 
and equal and with the overloaded operators opOpAssign and 
opSlice, even they are not obvious.

Preallocating global exceptions with standard messages is not a 
good idea.




More information about the Digitalmars-d mailing list