starwiz Posted July 15, 2003 Posted July 15, 2003 (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 July 16, 2003 by starwiz Quote
*Experts* Volte Posted July 15, 2003 *Experts* Posted July 15, 2003 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. Quote
starwiz Posted July 15, 2003 Author Posted July 15, 2003 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? Quote
*Gurus* Derek Stone Posted July 16, 2003 *Gurus* Posted July 16, 2003 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. Quote Posting Guidelines
*Experts* Volte Posted July 16, 2003 *Experts* Posted July 16, 2003 -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. Quote
starwiz Posted July 16, 2003 Author Posted July 16, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.