Changeing return type of struct.toString()
code at benjamin-thaut.de
Sun Feb 12 22:06:52 PST 2012
Am 13.02.2012 03:21, schrieb Don:
> On 12.02.2012 19:36, Benjamin Thaut wrote:
>> I'm currently trying to use D without a gc and didn't have major
>> problems so far. A minor issues is that struct.toString() returns a
>> string and this will almost allways leak memory when this is called.
>> The question now is, can I change the return type of struct.toString()
>> somewhere inside druntime or is it hardcoded in the compiler?
>> It was possible without any problems to change the return type of
>> Object.toString() and therefore every class in D because Object is the
>> baseclass for every class. Is there something similar for structs?
>> Kind Regards
>> Benjamin Thaut
> I don't know why struct toString() still exists. It's a legacy from the
> very beginning of D, back when the language didn't even have templates.
> std.format doesn't even require it, any more.
Well TypeInfo_struct declarers a delegate for the xtostring member which
returns a char. So I'm curiours if the compiler fills that member, and
if it does any checking on the toString() method while doing so.
Basically I have 2 string types now:
1) string = garantueed to be either in static memory or to outlive every
object that has a reference to it
2) rcstring = reference counted string (you have to use the most ugly
casts you can think of to actually make reference counting possible with
the D typesystem)
More information about the Digitalmars-d