Equivalency to constant arrays?

starwiz

Newcomer
Joined
Jul 2, 2003
Messages
21
[Resolved] Equivalency to constant arrays?

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
 
Last edited:
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.
 
VolteFace said:
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?
 
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.
 
-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.
 
VolteFace said:
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.
 
Back
Top