Equivalency to constant arrays?

starwiz

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

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

I have a dynamic array to which I assign values at design time (its the user-friendly--i.e. capitalized, spaced, and not abbreviated--names of the columns in a DB of mine) and never change. Im 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 Im 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 by a moderator:
No, not really. You cant make a constant with an array type (or any class type, for that matter). Dont worry though, having an array which is dynamic rather than static wont exactly hit your program with a speed decrease. You wont notice anything at all.

And a constant doesnt use less memory anyway (as far as I know, anyway)... a constant integer takes up 4 bytes, just as a regular integer does.
 
Originally posted by VolteFace
And a constant doesnt use less memory anyway (as far as I know, anyway)... a constant integer takes up 4 bytes, just as a regular integer does.

It doesnt replace the value of the constant into the code before it compiles it? That would only make sense...why wouldnt 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 starwizs post -- Derek snuck in whilst I was typing.
-/edit-

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

Regardless, I doubt youll see a different either way.
 
Originally posted by VolteFace
They may do, Im not sure. I know that this is what #define does in C++, but then again, const also exists in C++. Im not exactly sure.
Thats true, and one can make objects const in C++, so I doubt it inserts their values at compile time.

Im glad I dont have to worry about speed or memory problems with these arrays. Thanks for all the help, guys; I appreciate it.
 
Back
Top