Array types and index types

H. S. Teoh hsteoh at qfbox.info
Wed Feb 28 03:15:23 UTC 2024


On Wed, Feb 28, 2024 at 03:00:55AM +0000, Liam McGillivray via Digitalmars-d-learn wrote:
> In D, it appears that dynamic arrays (at least by default) use a ulong
> as their key type. They are declared like this:
> ```
> string[] dynamicArray;
> ```
> 
> I imagine that using a 64-bit value as the key would be slower than
> using 32 bits or 16 bits,

Wrong. The machine uses 64 bits internally anyway.  Well, 48 on i386.
But the point is that there is no speed difference.

Also, on 32-bit architectures size_t is aliased to uint, which is 32
bits.


[...]
> So I have some questions:
> 
> Is there a way to declare a dynamic array with a uint, ushort, or ubyte key?

No.


> If there was, would it really be faster?

No.


> Is an associative array with a ushort key faster than a dynamic array
> with a ulong key?

No.


T

-- 
Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANG


More information about the Digitalmars-d-learn mailing list