On Thu, May 24, 2012 at 5:26 AM, Jonathan S. Shapiro <[email protected]> wrote:
> On Thu, May 17, 2012 at 1:50 AM, Bennie Kloosteman <[email protected]>
> wrote:
>>
>> In the context of unsafe I thought people might find this interesting...
>>
>> I have been looking at C# strings and its quite obvious that what they
>> really wanted was a value type ( for performance reasons) that is
>> normally passed by reference...
>
>
> I don't think they wanted a value type. As you say, they wanted it to be
> passed by reference (and also immutable), so that's a reference (boxed)
> type. What I do think (and what I suspect you meant) is that they did not
> want to accept the *additional* indirection that is often present in vector
> implementations, where the "C" rendition of the structure looks something
> like:
>
> struct VectorOfFoo {
> int length; // fixed at creation
> Foo* vectorPayload;
> };
>
> The reason for the added indirection mainly has to do with the runtime-level
> implementation of larger objects - it ensures that there is exactly one live
> reference to the payload data, which makes compacting BigSpace easier.
Yes exactly they used some unsafe code to avoid this indirection.
Which also means the GC doesn't need to check the reference , you
also get better locality. Though since the size is arbitrary it needs
some hacks in the runtime.
>
> Once we get beyond that issue, the main reason to distinguish String from
> array<UniChar> has to do with (a) some semantics distinctions, and (b)
> encapsulating internal decisions about string encoding.
What I was really asking why not String : array<UniChar> { SubStr
etc.. } . With mutable /immutable semantics its gets more interesting.
immutable array<UniChar> with some extention methods would be very
similar and the issue with extention methods is worth it since it
means you can convert it to a mutable array for heavy string indexing
work very cheaply but yes you do want immutable array<UniChar> to be a
different type .
Note b) was desired but is a bit broken ( especially in mono due to
exposing the index property and the large amount of classes that
look into the internals for performance reasons StringBuilder ,
Culture based code etc. As strings are so important for performance
exposing the internals will happen , even within the runtime it does
create a mess so maybe allow a cast to mutable ( which should be a
different type) is a good idea .
>
>
> This is actually a good example of a place where having a Nat kind helps.
That lost me …I can make some guesses but I don't think your referring
to natural number type .
Ben
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev