Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

[PLAIN][Resolved] Equivalency to constant arrays?[/PLAIN]

 

In VB.net (and, I assume, C#), we can't create constant arrays...I guess that limitation makes sense.

 

I have a dynamic array to which I assign values at design time (it's the user-friendly--i.e. capitalized, spaced, and not abbreviated--names of the columns in a DB of mine) and never change. I'm trying, however, to save a little bit of memory and processing power in my program, and could if I had a constant substitute for the dynamic array that I'm using right now.

 

I need to be able to reference my values by an index (thus my use of an array in my first design). Is there something that I can easily substitute for my dynamic array that will make my program faster and use less memory?

 

Thanks a lot for your help,

-Starwiz

Edited by starwiz
  • *Experts*
Posted

No, not really. You can't make a constant with an array type (or any class type, for that matter). Don't worry though, having an array which is dynamic rather than static won't exactly hit your program with a speed decrease. You won't notice anything at all.

 

And a constant doesn't use less memory anyway (as far as I know, anyway)... a constant integer takes up 4 bytes, just as a regular integer does.

Posted
And a constant doesn't use less memory anyway (as far as I know, anyway)... a constant integer takes up 4 bytes, just as a regular integer does.

 

It doesn't replace the value of the constant into the code before it compiles it? That would only make sense...why wouldn't they substitute the constant names for their values before compilation?

  • *Gurus*
Posted
Constant or no constant the variable will be replaced with its value prior to execution. The JIT (just-in-time) compiler does an excellent job of optimizing code. Any slow downs in .NET are caused by poorly written algorithms, not minor issues such as constants.
  • *Experts*
Posted

-edit-

I was referring to starwiz's post -- Derek snuck in whilst I was typing.

-/edit-

 

They may do, I'm not sure. I know that this is what #define does in C++, but then again, const also exists in C++. I'm not exactly sure.

 

Regardless, I doubt you'll see a different either way.

Posted
They may do, I'm not sure. I know that this is what #define does in C++, but then again, const also exists in C++. I'm not exactly sure.

That's true, and one can make objects const in C++, so I doubt it inserts their values at compile time.

 

I'm glad I don't have to worry about speed or memory problems with these arrays. Thanks for all the help, guys; I appreciate it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...