July 09, 2009
Tim Matthews Wrote:

> I thought a slice would behave slighty different due to some sort of meta data that is a separate area of memory so it doesn't effect D's abi.
> 
Current plan is to introduce new type - array - into the language.
July 09, 2009
Kagamin wrote:
> Tim Matthews Wrote:
> 
>> I thought a slice would behave slighty different due to some sort of meta data that is a separate area of memory so it doesn't effect D's abi.
>>
> Current plan is to introduce new type - array - into the language.

Do you know the ng posts or where ever that was posted?
July 09, 2009

Tim Matthews wrote:
> Kagamin wrote:
>> Tim Matthews Wrote:
>>
>>> I thought a slice would behave slighty different due to some sort of meta data that is a separate area of memory so it doesn't effect D's abi.
>>>
>> Current plan is to introduce new type - array - into the language.
> 
> Do you know the ng posts or where ever that was posted?

Best bet would be to search for "T[new]".
July 09, 2009
Hello Tim,

> BCS wrote:
> 
>> Hello Tim,
>> 
>>> Anyway I like how you can get a slice of array that is just a view
>>> into the original. If I modify the slice, it modifies the full
>>> original array which can be very useful. If however I modify the
>>> length of the slice which I was doing in an attempt to extend the
>>> view, it becomes it's own array.
>>> 
>> [...]
>> 
>>> Was this a design choice, bug, undefined behavior, etc...?
>>> 
>> you can grab a larger chunk like this
>> 
>> char[] buff1 = something;
>> char[] buff2 = buff1[10..20];
>> buff2 = buff2.ptr[0..20];
>> 
>> note this is unsafe and will give you no warnings if you extend past
>> the end of buff1;
>> 
> I know that but I when I said I was trying to extend the view I really
> mean that I was just trying to extend the view.

If that doesn't "extend the view", then I'm not understanding what you are asking for.

the above should compile to the sudocode:

t = &(buff.ptr[0]);
L = 20-0;
buff2.{ptr, length} = {t, L};

and should optimize to just an assignment to length.

> Also depending on what
> news reader you use you should see that it branched off in a
> particular direction to a solution.
> 

If you are referring the your response to Steven Schveighoffer, that amounts to the same thing I proposed but is even less safe (I don't think the layout of an array reference is speced) and harder to understand.


July 09, 2009
Sorry I misread (lacking sleep). I can just re slice from the slice, silly me.

import std.stdio;

void extendSlice(T)(ref T[] slice, uint extendCount)
{
    slice = slice.ptr[0..slice.length+extendCount];
}

void main()
{
    char[] a = "Hello".dup;
    char[] b;
    b = a[1..3]; //b is a view into a
    writeln(a); //(Hello)
    writeln(b); //(el)
    extendSlice(b,1);
    writeln(a); //(Hello)
    writeln(b); //(ell)
}
July 09, 2009
Hello Tim,

> Sorry I misread (lacking sleep).

Been there, done that. :oz


July 09, 2009
Daniel Keep wrote:
> 
> Tim Matthews wrote:
>> Kagamin wrote:
>>> Tim Matthews Wrote:
>>>
>>>> I thought a slice would behave slighty different due to some sort of
>>>> meta data that is a separate area of memory so it doesn't effect D's
>>>> abi.
>>>>
>>> Current plan is to introduce new type - array - into the language.
>> Do you know the ng posts or where ever that was posted?
> 
> Best bet would be to search for "T[new]".

Superseded by Andrei's Array struct.
1 2
Next ›   Last »