Board index » delphi » Big typed constant array definition?

Big typed constant array definition?

Hi!

At the moment I am using constant array definition:

const arrayname: array[0..255] of dword = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);

I wonder if there is some more sensible way to get an array filled with
same values (besides using FOR cycle)? I am using FreePascal compiler...

Reaper

 

Re:Big typed constant array definition?


Quote
Imot Algma wrote:

> At the moment I am using constant array definition:

> const arrayname: array[0..255] of dword = (0,...,0);

> I wonder if there is some more sensible way to get an array filled with
> same values (besides using FOR cycle)? I am using FreePascal compiler...

Hm...
what about

var arrayname: ...
FillChar(arrayname,sizeof(arrayname),0);

//or better: (FPC only and sizeof(...) must be even)
FillWord(arrayname,sizeof(arrayname) div 2,0);

Wolf

Re:Big typed constant array definition?


Quote
In article <3EC02147.5F161...@gmx.net>, Wolf Behrenhoff wrote:
> Imot Algma wrote:

>> At the moment I am using constant array definition:

>> const arrayname: array[0..255] of dword = (0,...,0);

>> I wonder if there is some more sensible way to get an array filled with
>> same values (besides using FOR cycle)? I am using FreePascal compiler...

> Hm...
> what about

> var arrayname: ...
> FillChar(arrayname,sizeof(arrayname),0);

> //or better: (FPC only and sizeof(...) must be even)
> FillWord(arrayname,sizeof(arrayname) div 2,0);

Hmm, fpc is a 32-bitter,  (array must be divisable by 4)

FillDWord (arrayname(sizeof(arrayname) div 4,0);

Re:Big typed constant array definition?


On Tue, 13 May 2003, Marco van de Voort wrote:

Quote
> In article <3EC02147.5F161...@gmx.net>, Wolf Behrenhoff wrote:
> > Imot Algma wrote:

> >> At the moment I am using constant array definition:

> >> const arrayname: array[0..255] of dword = (0,...,0);

> >> I wonder if there is some more sensible way to get an array filled with
> >> same values (besides using FOR cycle)? I am using FreePascal compiler...

> > Hm...
> > what about

> > var arrayname: ...
> > FillChar(arrayname,sizeof(arrayname),0);

> > //or better: (FPC only and sizeof(...) must be even)
> > FillWord(arrayname,sizeof(arrayname) div 2,0);

> Hmm, fpc is a 32-bitter,  (array must be divisable by 4)

> FillDWord (arrayname(sizeof(arrayname) div 4,0);

Ok, but what is faster, FillDWord or constant array definition in the
beginning? I thought there would be some shorter way to write all those
zeros, like (0,...,0)?

Reaper

Re:Big typed constant array definition?


Quote
In article <Pine.BSF.4.53.0305142110580.37...@vega.et.ee>, Imot Algma wrote:

>> FillDWord (arrayname(sizeof(arrayname) div 4,0);

> Ok, but what is faster, FillDWord or constant array definition in the
> beginning? I thought there would be some shorter way to write all those
> zeros, like (0,...,0)?

Constant. Unless it gets that large that it affects program loading, which
is hard to estimate, but probably not until 100's of kbs.

Other Threads