Escaping the Tyranny of the GC: std.rcstring, first blood
Paulo Pinto via Digitalmars-d
digitalmars-d at puremagic.com
Thu Sep 25 02:25:33 PDT 2014
On Thursday, 25 September 2014 at 05:46:35 UTC, Walter Bright
wrote:
> On 9/24/2014 1:15 PM, Manu via Digitalmars-d wrote:
>> Something like (whatever syntax you like):
>>
>> int^ rcInt; // refcounted pointer to an int
>> MyStruct^ rcStruct; // refcounted pointer to a struct
>> MyStruct s; // normal value-type struct, but if the struct has
>> opInc/opDec, the RC handling code in the compiler can
>> implicitly
>> generate calls to opInc/opDec on assignment, which will allow
>> the
>> struct to manage itself.
>
> I think Microsoft's C++/CLI tried that mixed pointer approach,
> and it was a disaster. I don't have personal knowledge of this.
>
> I suspect I know why. C++ on DOS had mixed pointer types - the
> near and far thing. It was simply unworkable in C++. Sure, it
> technically worked, but was so awful trying to deal with "is my
> ref type near or far" that people just couldn't write
> comprehensible code with it.
>
> Note that a ^ pointer will be a different size than a *
> pointer. Things go downhill from there.
Why it was a disaster? Microsoft is still using it.
It is how C++/CX works, recently introduced with Windows 8 new
COM based runtime.
The different to C++/CLI being that ^ (handle types) are not GC
pointers, but rather compiler managed COM (AddRef/Release)
instances.
For those that wish to stay away from C++/CX, there is the more
complex Windows Runtime C++ Template Library with ComPtr<>(), but
then bye compiler support for increment/decrement removals.
http://msdn.microsoft.com/en-us/library/hh699870.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/jj822931.aspx
Example for those lazy to follow the link,
using namespace Platform;
Person^ p = ref new Person("Clark Kent");
p->AddPhoneNumber("Home", "425-555-4567");
p->AddPhoneNumber("Work", "206-555-9999");
String^ workphone = p->PhoneNumbers->Lookup("Work");
--
Paulo
More information about the Digitalmars-d
mailing list