View mode: basic / threaded / horizontal-split · Log in · Help
August 06, 2007
2/3 dimensional arrays + comparison page truncated
A few things. Firstly, what's happened to the main comparison page:
http://www.digitalmars.com/d/comparison.html

It's only showing stats for D.

Second thing. How does D allocate for a 2D (or even 3D) array. I tried to look everywhere on the D site for this, and nothing came up. I'm just curious to how it compares with the long-winded C/C++ way of using malloc to create arrays.

Lastly, is there a place which shows all of the D commands with a short description? What would be great too is if they were all sorted by how often each command is used.
August 06, 2007
Re: 2/3 dimensional arrays + comparison page truncated
Daniel White wrote:
> A few things. Firstly, what's happened to the main comparison page:
> http://www.digitalmars.com/d/comparison.html
> 
> It's only showing stats for D.

Hm.  Dunno.

> Second thing. How does D allocate for a 2D (or even 3D) array. I tried to look everywhere on the D site for this, and nothing came up. I'm just curious to how it compares with the long-winded C/C++ way of using malloc to create arrays.

Well... it sorta depends.  For static/fixed-length arrays:
int[5][10] foo;
x = foo[2][3];

Its the same as this:
int[50] foo;
x = foo[(2 * 10) + 3];

At least in terms of memory layout.  The difference is in how it 
interacts with slices, typeinfo, and the meaning of the .length property.

Dynamic/variable-length arrays, on the other hand, are structures of a 
length and pointer to heap memory.  So its best to say there /are no/ 
multi-dimensional dynamic arrays -- but there /are/ arrays whose element 
type is itself an array.  A subtle difference.


> Lastly, is there a place which shows all of the D commands with a short description? What would be great too is if they were all sorted by how often each command is used.

Someone was maintaining a D keyword glossary at one time, and might 
still be, but I be darned if I can remember a link to it.  -_- 
Hopefully someone else has it bookmarked.

-- Chris Nicholson-Sauls
August 06, 2007
Re: 2/3 dimensional arrays + comparison page truncated
Daniel White wrote:
> A few things. Firstly, what's happened to the main comparison page: 
> http://www.digitalmars.com/d/comparison.html
> 
> It's only showing stats for D.

It got tonnes of complaints by non-D users about how their languages were being
misrepresented. In the end, it was decided to take them out completely.

> Lastly, is there a place which shows all of the D commands with a short
> description? What would be great too is if they were all sorted by how often
> each command is used.

http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex

prowiki.org is down now, though, so you can't see it. Google has a cache:

http://www.google.com/search?q=cache:QgZctJ2jkQUJ:http://www.prowiki.org/wiki4d/wiki.cgi%3FLanguageSpecification/KeywordIndex

-- 
Remove ".doesnotlike.spam" from the mail address.
August 06, 2007
Re: 2/3 dimensional arrays + comparison page truncated
Chris Nicholson-Sauls wrote:
> Someone was maintaining a D keyword glossary at one time, and might 
> still be, but I be darned if I can remember a link to it.  -_- Hopefully 
> someone else has it bookmarked.

That would be me, and I still am. :-)

As Deewiant mentioned, it's on Wiki4D, but that site is down. The Google 
cache is slightly out of date (it is missing __traits), but still 
serviceable.

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
August 06, 2007
Re: 2/3 dimensional arrays + comparison page truncated
Kirk McDonald wrote:
> Chris Nicholson-Sauls wrote:
>> Someone was maintaining a D keyword glossary at one time, and might 
>> still be, but I be darned if I can remember a link to it.  -_- 
>> Hopefully someone else has it bookmarked.
> 
> That would be me, and I still am. :-)
> 
> As Deewiant mentioned, it's on Wiki4D, but that site is down. The Google 
> cache is slightly out of date (it is missing __traits), but still 
> serviceable.
> 

And I'm off to bookmark the link anyhow, so I /will/ have it next time 
it comes up.  :)  Thanks for doing that, by the way, even if I haven't 
used it often.

-- Chris Nicholson-Sauls
August 07, 2007
Re: 2/3 dimensional arrays + comparison page truncated
Kirk McDonald wrote:
> Chris Nicholson-Sauls wrote:
>> Someone was maintaining a D keyword glossary at one time, and might 
>> still be, but I be darned if I can remember a link to it.  -_- 
>> Hopefully someone else has it bookmarked.
> 
> That would be me, and I still am. :-)
> 
> As Deewiant mentioned, it's on Wiki4D, but that site is down. The Google 
> cache is slightly out of date (it is missing __traits), but still 
> serviceable.
> 

I did not know that existed.  That actually sounds very useful, 
especially for showing newbies how to use D.

I learned most of that by cross-referencing the NG with the digital mars 
site and with simple compiler tests.  But that's the slow way ;)

Thanks for making such a glossary.
August 07, 2007
Re: 2/3 dimensional arrays + comparison page truncated
"Daniel White" <twinbee41@skytopia.com> wrote in message 
news:f96gar$1vjv$1@digitalmars.com...
> Second thing. How does D allocate for a 2D (or even 3D) array. I tried to 
> look everywhere on the D site for this, and nothing came up. I'm just 
> curious to how it compares with the long-winded C/C++ way of using malloc 
> to create arrays.

Try this:

import std.stdio;
void main()
{
   int[][]   arr2d = new int[][](10,10);
   foreach(d; arr2d)
   {
       foreach(ref x; d)
       {
           x = 2;
       }
   }
   foreach(d; arr2d)
   {
       foreach(x; d)
       {
           writef(x);
       }
       writefln;
   }
   int[][][] arr3d = new int[][][](10,10,10);
   foreach(d2; arr3d)
   {
       foreach(d; d2)
       {
           foreach(ref x; d)
           {
               x = 3;
           }
       }
   }
   foreach(d2; arr3d)
   {
       foreach(d; d2)
       {
           foreach(x; d)
           {
               writef(x);
           }
           writef(" ");
       }
       writefln;
   }
}
August 07, 2007
Re: 2/3 dimensional arrays + comparison page truncated
"Daniel White" <twinbee41@skytopia.com> wrote in message
news:f96gar$1vjv$1@digitalmars.com...
> Second thing. How does D allocate for a 2D (or even 3D) array. I tried to
> look everywhere on the D site for this, and nothing came up. I'm just
> curious to how it compares with the long-winded C/C++ way of using malloc
> to create arrays.

Try this:

import std.stdio;
void main()
{
   int[][]   arr2d = new int[][](10,10);
   foreach(d; arr2d)
   {
       foreach(ref x; d)
       {
           x = 2;
       }
   }
   foreach(d; arr2d)
   {
       foreach(x; d)
       {
           writef(x);
       }
       writefln;
   }
   int[][][] arr3d = new int[][][](10,10,10);
   foreach(d2; arr3d)
   {
       foreach(d; d2)
       {
           foreach(ref x; d)
           {
               x = 3;
           }
       }
   }
   foreach(d2; arr3d)
   {
       foreach(d; d2)
       {
           foreach(x; d)
           {
               writef(x);
           }
           writef(" ");
       }
       writefln;
   }
}
August 09, 2007
Re: 2/3 dimensional arrays + comparison page truncated
Deewiant wrote:
> Daniel White wrote:
>> A few things. Firstly, what's happened to the main comparison page: 
>> http://www.digitalmars.com/d/comparison.html
>>
>> It's only showing stats for D.
> 
> It got tonnes of complaints by non-D users about how their languages were being
> misrepresented. In the end, it was decided to take them out completely.
> 
I think it was when DMD finally hit 1.0 (and thus got some extra 
attention). People would complain that "their" language indeed do have 
(insert feature here) and then show a two-page example on how to do this 
 via the language's standard library. Usually a D user would then point 
out somewhat smugly that the comparison page states that only language 
 features are compared - standard libraries are not included in the 
comparison. Although this may be true, the discussion would usually 
degenerate from there into some form of flame war with hurt feelings and 
bruised egos.
Programmers can be very dogmatic like that sometimes. Just as other 
people we tend to mix up what we do with who we are. I think it was 
decided that although the comparison page was technically correct, it 
had to be "truncated" a bit in the interests of public relations.
Top | Discussion index | About this forum | D home