Re: Array slice length confusion

2009-07-09 Thread grauzone
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 yo

Re: Array slice length confusion

2009-07-09 Thread BCS
Hello Tim, Sorry I misread (lacking sleep). Been there, done that. :oz

Re: Array slice length confusion

2009-07-09 Thread Tim Matthews
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 i

Re: Array slice length confusion

2009-07-09 Thread BCS
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 th

Re: Array slice length confusion

2009-07-09 Thread Daniel Keep
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. > >

Re: Array slice length confusion

2009-07-09 Thread Tim Matthews
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 w

Re: Array slice length confusion

2009-07-09 Thread Kagamin
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.

Re: Array slice length confusion

2009-07-09 Thread Tim Matthews
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 bec

Re: Array slice length confusion

2009-07-08 Thread BCS
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 ow

Re: Array slice length confusion

2009-07-08 Thread Tim Matthews
Steven Schveighoffer wrote: This is really not a good idea. You've removed one of the core features of the array -- memory safety. Doing this is just asking for memory corruption. You should either re-slice the original array, or create a type that has a reference to the original array so it

Re: Array slice length confusion

2009-07-08 Thread Steven Schveighoffer
On Wed, 08 Jul 2009 23:09:52 -0400, Tim Matthews wrote: Steven Schveighoffer wrote: On Wed, 08 Jul 2009 02:48:31 -0400, Tim Matthews wrote: Was this a design choice, bug, undefined behavior, etc...? design choice. A slice *is* an array in the current design. Increasing the length

Re: Array slice length confusion

2009-07-08 Thread Tim Matthews
Steven Schveighoffer wrote: On Wed, 08 Jul 2009 02:48:31 -0400, Tim Matthews wrote: Was this a design choice, bug, undefined behavior, etc...? design choice. A slice *is* an array in the current design. Increasing the length may or may not make a copy of it. An array slice doesn't know

Re: Array slice length confusion

2009-07-08 Thread Tim Matthews
Kagamin wrote: For this I use begin markers: ubyte[] buff=new ubyte[100]; int half=buff.length/2; ubyte[] buff1=buff[0..half]; ubyte[] buff2=buff[half..$]; I actually think this has nothing to do with my OP.

Re: Array slice length confusion

2009-07-08 Thread Kagamin
Kagamin Wrote: > Tim Matthews Wrote: > > > Was this a design choice, bug, undefined behavior, etc...? > > Design choice. In order to widen slice to should recreate it from the > original array. For this I use begin markers: ubyte[] buff=new ubyte[100]; int half=buff.length/2; ubyte[] buff1=bu

Re: Array slice length confusion

2009-07-08 Thread Kagamin
Tim Matthews Wrote: > Was this a design choice, bug, undefined behavior, etc...? Design choice. In order to widen slice to should recreate it from the original array.

Array slice length confusion

2009-07-07 Thread Tim Matthews
First off if this has been asked so many times please just ignore this. You should be able to collapse this whole subject in most good new readers plus it is in d.learn out of the way so I expect no "ahh here we go again" sort of replies. Anyway I like how you can get a slice of array that is