shuffle a character array

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 20 01:30:37 PDT 2016


On Wednesday, 20 July 2016 at 08:18:55 UTC, celavek wrote:

>
> As far as my current understanding goes the shuffle will be 
> done in place.
> If I use the "representation" would that still hold, that is 
> will I be able
> to use the same char[] but in the shuffled form? (of course I 
> will test that)

representation does not allocate any new memory. It points to the 
same memory, same data. If we think of D arrays as something like 
this:

struct Array(T) {
     size_t len;
     T* ptr;
}

Then representation is doing this:

Array original;
Array representation(original.len, original.ptr);

So, yes, the char data will still be shuffled in place. All 
you're doing is getting a ubyte view onto it so that it can be 
treated as a range.


More information about the Digitalmars-d-learn mailing list