Re: How to do "Compile time" initialization of record array?



Jon,

For example, one of my "C" programs has

struct
{
double L;
double M;
double S;
} LengthArray[] = {
{ 1.267004226, 49.988884080, 0.053112191}, // 1
{ 0.511237696, 52.695975300, 0.048692684}, // 2
{ -0.452244460, 56.628428550, 0.044116830}, // 3

This is some statistical data (there are 76 records per array) and I have
Length, Weight, and Circumference arrays.

I typically am targeting some low "horsepower" handheld devices.

Even in C, I could run time initialize my arrays but I didn't for at least a
couple of reasons...
1) Performance, why waste runtime cycles building an array when it could be
pre-built by the compiler
2) Run time building meant that I carried two copies of my data in the
"execution footprint". One copy in code segment and the other copy in the
data segment.

I understand that this really doesn't present a challenge to a modern
device, especially in a desktop environment, it was just a style I have/had.

I don't understand C# the way I do C. Things that used to be important, no
longer seem to matter as much.

I've appreciated all of the responses and I'm certain I'll ask more "old
fashioned" questions as I learn.

Thanks,
John Kelsey

"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1e1f8db44156943698cc2b@xxxxxxxxxxxxxxxxxxxxxxx
> John Kelsey <kelseyj@xxxxxxxxxx> wrote:
--snip--
>>
>> I guess it boils down to the difference between
>> int i = 32;
>>
>> and
>> int i;
>> ...
>> i = 32;
>
> Well, in that case there really isn't any difference in the compiled
> code, as far as I'm aware. I know what you mean though :)
>
>> Is this any clearer?
>
> While I see what you mean, there isn't a way of doing it that I know of
> in C#, nor do I suspect it's really a problem. Do you have any
> particular reason for desiring it from an execution point of view? You
> can achieve the same "end goal" (getting an initialised array) in C#
> with quite similar code, so it's only the matter of when it actually
> gets built which is significantly different. Are you worried about
> performance?
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too


.



Relevant Pages

  • Re: Comparison to Comparison
    ... alive", no matter how long you wait after the Collect call, and no ... regardless of the size of the array. ... As near as I can tell, the issue is that when you assign into the objectas part of the argument to the WeakReference constructor, the compiler generates a hidden local variable. ... But, absent a more invasive inspection of the execution of the code, I'd admit that even your code example isn't proof of that. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Cost of calling a standard library function
    ... BetovAsm does not handle structures so you must use an array instead. ... other more complex data managing methods and it will be to your ... It does not matter if you are writing in NASM, FASM, MASM, TASM, ... whether you have enough capacity to learn how to do the more difficult ...
    (alt.lang.asm)
  • Re: FAQ Topic - What online resources are available? (2009-01-29)
    ... "it doesn't work in this browser." ... remaining warning is the missing type in the script tag. ... videos, vs. a 0.1% that's arguable, or a matter of tastes. ... The term 'array' was used to mean something that is not a javascript ...
    (comp.lang.javascript)
  • Re: why did Abdellah record in accordance with all the musics? We cant tear attributes unless Charle
    ... Plenty of compatible damp corruptions on board threaten as the necessary burdens part. ... We double no matter how if Zachary's array isn't technical. ... We sum the competitive remedy. ...
    (sci.crypt)
  • Re: ARRAY EQUATION VS FORALL
    ... I personally dislike this style. ... It is mostly a matter of style choice ... B is a whole array, ... The slice happens to include all of the same elements, ...
    (comp.lang.fortran)