January 31, 2008 Re: static array length | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | "Saaa" <empty@needmail.com> wrote in message news:fnsmjb$1vsq$1@digitalmars.com... > If I'd know the lenght I would just do :) > > c[0 .. 4] = `1234`; > writefln( c[0 .. 4]); > > I'm looking into making use of: > struct charS{ > char c; > int leng; > } So, in other words, you're re-implementing dynamic arrays? What I'm wondering is why you need this? What is it that you're trying to do? |
January 31, 2008 Re: static array length | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Except that it will be on the stack :)
I'll be testing the speed difference.
>
> So, in other words, you're re-implementing dynamic arrays?
>
> What I'm wondering is why you need this? What is it that you're trying to do?
>
|
February 01, 2008 Re: static array length | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | "Saaa" <empty@needmail.com> wrote in message news:fntlub$1iq8$1@digitalmars.com... > Except that it will be on the stack :) > > I'll be testing the speed difference. So you want a string buffer on the stack, or what? If it's on the stack and you're doing a lot of operations that would otherwise involve concatenations, it'll be faster. If it's in a function that's called a lot, it'll be faster, since no heap allocation will occur. But, then you're limited by the size of the array, and you can't use the same things -- no concatenations, namely. It's a tradeoff of syntactic niceness and flexibility of size vs. speed. |
February 01, 2008 Re: static array length | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Saaa:
> I'll be testing the speed difference.
You can allocate memory on the stack with alloca() too.
It may sound strange, but iterating on a dynamic array is often a bit faster.
Bye,
bearophile
|
February 01, 2008 Re: static array length | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | Yes, that does sound strange.
Do you know why this is the case?
>
> You can allocate memory on the stack with alloca() too.
> It may sound strange, but iterating on a dynamic array is often a bit
> faster.
>
> Bye,
> bearophile
|
February 01, 2008 Re: static array length | ||||
---|---|---|---|---|
| ||||
Posted in reply to Saaa | Saaa:
> Yes, that does sound strange.
> Do you know why this is the case?
I don't know why, but you can write a little benchmark in 5 minutes to see if it's true on your PC too :-)
Bye,
bearophile
|
February 01, 2008 Re: static array length | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | I'll do that, but my computer isn't that prototypical that I can use the outcome as a standard for all my customers :D
>> Yes, that does sound strange.
>> Do you know why this is the case?
>
> I don't know why, but you can write a little benchmark in 5 minutes to see if it's true on your PC too :-)
>
> Bye,
> bearophile
|
Copyright © 1999-2021 by the D Language Foundation