arrays && functions && pointers
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Jun 18 19:32:49 PDT 2006
"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
news:e751ri$2709$1 at digitaldaemon.com...
>> btw. How do I reset all the data of a rectangular array?
>> something like:
>> tiles[][]=0;
Damn news client. Ctrl + Enter posts, apparently.
I assume your array is of a static size (thus making it a rectangular
array). You can do this:
foreach(/* auto */ a; tiles)
a[] = 0;
(I just put the /* auto */ in there to let me know when I'm using the dirty,
nonobvious foreach index type inference)
Or, and this is a little hackish, but you can take advantage of the layout
of rectangular arrays, which is a single block of memory:
((cast(TILE*)tiles.ptr)[0 .. TILEW * TILEH])[] = 0;
Basically, you're converting the rectangular array type into a linear array
type, and setting all those elements to 0. I would imagine this would be
somewhat faster, since it's doing one block set, rather than one block for
each row.
More information about the Digitalmars-d-learn
mailing list