size_t for length on x64 will make app slower than on x86?
Marco Leise via Digitalmars-d
digitalmars-d at puremagic.com
Tue Nov 18 11:27:50 PST 2014
Am Tue, 18 Nov 2014 12:22:58 +0000
schrieb "FrankLike" <1150015857 at qq.com>:
>
> >> I mean projects moved from x86 to x64, 'cast(int)length ' is
> >> better than 'size_t i=(something).length '.
> >
> > I think the reason for the existence of size_t, is that the C
> > designers thought that the second way is better than the first
> > way.
>
> But now 'int' is enough, not huge and not small.
>
> if you do this:
>
> string[] a ={"abc","def","ghk"... };//Assuming a's length is
> 1,000,000
>
> for(int i=0;i<a.length;i++)
> {
> somework();
> }
>
> it's enough! 'int' easy to write,not Waste.
>
> Most important is easy to migrate code from x86 to x64.
Somehow I always wrote that as
foreach (i; 0 .. a.length)
{
somework();
}
and benefited from the fact that the compiler only needs to
evaluate a.length once as opposed to the for(...) case.
--
Marco
More information about the Digitalmars-d
mailing list