*PROB* Using Segments to mess with local arrays: - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: *PROB* Using Segments to mess with local arrays: (/thread-2069.html) Pages:
1
2
|
*PROB* Using Segments to mess with local arrays: - seph - 09-25-2003 Okay I made a little test program that can create an array inside a SUB, get the segment address (assuming the offset is 0) and the mess with that array ANYWHERE else in the entire program. I personally thought this was the most kickass thing in the world (because it's so new to me and) because I don't even need an array's fricken name in order to use it!!!! This is particularly handy when you need an array that you can resize the dimensions of (REDIM for use with maps that vary in size) and when that array is inside a TYPE (because you can't do that with static arrays unfortunately). Unfortunately, it is a mystery to me why my attempt to impliment this into my heavily-UGL utilizing program failed. SEGMENTS.BAS Code: DECLARE FUNCTION GetInfo% (map AS ANY, x%, y%) As I look over this code after I had posted this message, I realize that I may have actually sort of "cheated" with this. I noticed that I didn't make the array a global one, so I'm starting to think that when it changes the array from inside that sub, it's actually leaving behind that old code, and simply allocating extra space. If this is the case, the code may be terribly inefficient, and I'll have to look it over again. Sorry in advance for any possible inconvience! P.S. boy golley do i sound weird when i tries t' sound profeshunal *PROB* Using Segments to mess with local arrays: - seph - 09-25-2003 Okay I think this may be a little better for gathering evidence for/against my theory: Code: DECLARE FUNCTION GetInfo% (map AS ANY, x%, y%) *PROB* Using Segments to mess with local arrays: - Sterling Christensen - 09-25-2003 After you create an array in a sub, the array dissappears once the program exits the sub. Try making the array STATIC. *PROB* Using Segments to mess with local arrays: - seph - 09-25-2003 Can you still REDIM a STATIC array? I thought you couldn't? *PROB* Using Segments to mess with local arrays: - Sterling Christensen - 09-25-2003 I just tested it. You can REDIM a STATIC array as long as it's dynamic. *PROB* Using Segments to mess with local arrays: - seph - 09-26-2003 Now I have a question about dynamic arrays... First, however, I'm gonna tell you the facts, as far as I know them. If ever 'm wrong, please explain why. Thanks. - Dynamic arrays are located at the same exact part of memory throughout your entire program. - You can access them throughout any SUB or FUNCTION as long as you have the segment address for it, because they don't move within memory. If those are true, then how are they different from SHARED arrays? I ask this because as a temporary solution, I've resorted to using one single shared array for my map, and I REDIM this map each time a level is loaded. So my question really is just, are dynamic arrays any better than shared arrays? *PROB* Using Segments to mess with local arrays: - relsoft - 09-30-2003 all arrays declared inside subs/functions are dynamic. *PROB* Using Segments to mess with local arrays: - seph - 10-01-2003 That doesn't answer my question of SHARED vs DYNAMIC. *BUMPA$$B1TCH* *PROB* Using Segments to mess with local arrays: - Sterling Christensen - 10-01-2003 EDIT: Oh wait, I just realized you probably misunderstood me. I meant declare it STATIC like this: Code: SUB mySub Original post (before edit): Quote:'$DYNAMIC arrays can move when you REDIM them, but overwise they stay put. *PROB* Using Segments to mess with local arrays: - seph - 10-01-2003 Soooo then declaring my array STATIC within the array will solve this problem? Also, what is the advantage of using this method rather than just declaring the array SHARED in the beginning of the program? Does it save space somehow? |