digitalmars.D.learn - painting arrays over arrays
- BCS (15/15) Aug 17 2005 Quite some time ago, I posted in one of these forums looking for a fast ...
- Derek Parnell (6/23) Aug 17 2005 No. That's basically what a few people said you needed to do.
- Derek Parnell (7/28) Aug 17 2005 Sorry, I tell a lie. Your solution is much better than the ones provided
Quite some time ago, I posted in one of these forums looking for a fast way to “paint” a dynamic array of one type (int[5][] for example) over a dynamic array of another type (int[]) several allocate-and-copy solutions were suggested, all to slow, to clunky, etc. I found a good solution (see below) what I’m wondering being or I did we all manage to not notice this one? // take an input of type F[] and return an output of type T[] that overlays the input template paint(T, F) { T[] paint(F[] data) { return (cast(T*)data.ptr)[0 .. data.length*F.sizeof/T.sizeof]; } }
Aug 17 2005
On Wed, 17 Aug 2005 20:05:43 +0000 (UTC), BCS wrote:Quite some time ago, I posted in one of these forums looking for a fast way to “paint” a dynamic array of one type (int[5][] for example) over a dynamic array of another type (int[]) several allocate-and-copy solutions were suggested, all to slow, to clunky, etc. I found a good solution (see below) what I’m wondering being or I did we all manage to not notice this one? // take an input of type F[] and return an output of type T[] that overlays the input template paint(T, F) { T[] paint(F[] data) { return (cast(T*)data.ptr)[0 .. data.length*F.sizeof/T.sizeof]; } }No. That's basically what a few people said you needed to do. -- Derek Parnell Melbourne, Australia 18/08/2005 7:08:39 AM
Aug 17 2005
On Thu, 18 Aug 2005 07:09:30 +1000, Derek Parnell wrote:On Wed, 17 Aug 2005 20:05:43 +0000 (UTC), BCS wrote:Sorry, I tell a lie. Your solution is much better than the ones provided earlier. -- Derek Parnell Melbourne, Australia 18/08/2005 7:21:23 AMQuite some time ago, I posted in one of these forums looking for a fast way to “paint” a dynamic array of one type (int[5][] for example) over a dynamic array of another type (int[]) several allocate-and-copy solutions were suggested, all to slow, to clunky, etc. I found a good solution (see below) what I’m wondering being or I did we all manage to not notice this one? // take an input of type F[] and return an output of type T[] that overlays the input template paint(T, F) { T[] paint(F[] data) { return (cast(T*)data.ptr)[0 .. data.length*F.sizeof/T.sizeof]; } }No. That's basically what a few people said you needed to do.
Aug 17 2005