REDIM takes more resources than DIM? - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: REDIM takes more resources than DIM? (/showthread.php?tid=2870) |
REDIM takes more resources than DIM? - bplus - 07-17-2024 Quote:REDIM arrays dynmicaly is not problem in small programs I was under impression by something Luke said, in previous forum I think or this one, that REDIM can replace all DIM statements without penalty in time or memory space. RE: REDIM takes more resources than DIM? - DSMan195276 - 07-17-2024 It's functionally the same, where is that quote from? They might be talking about using `REDIM` to resize existing arrays, in which case yes it is kinda expensive for larger arrays, mostly if you use `_PRESERVE`. If you're just replacing all your DIM statements with REDIM though then that wouldn't apply since you wouldn't have any resizes happening after the array is first declared. RE: REDIM takes more resources than DIM? - bplus - 07-17-2024 Yes thats probably it, I am thinking flat out substitution redim where there was dim, he maybe thinking _preserve operation. Thanks for your reply. Oh quote is from another forum, an O2 fan. RE: REDIM takes more resources than DIM? - SMcNeill - 07-17-2024 May also be an issue with having to reset array values to 0. TYPE foo x AS STRING y AS LONG END TYPE REDIM whatever(1000) AS foo I seem to remember that the above doesn't always initialize arrays to 0, so you may need to do so manually for that, leading to extra run time and such. RE: REDIM takes more resources than DIM? - SMcNeill - 07-17-2024 And it may be this: Code: (Select All)
RE: REDIM takes more resources than DIM? - Dimster - 07-17-2024 I have only used REDIM where my program was developing more data to add to an already filled array. Is there a circumstance where REDIM is being used other than to expand an existing array? Can't be used to ReName an existing array can it? ReDim Array1(50) as Array2(50) RE: REDIM takes more resources than DIM? - Kernelpanic - 07-17-2024 The function of Redim has been discussed ad nauseam here, but somehow it doesn't seem to get through. Again: A static array is set to zero with Erase. That's all you need. Redim cannot be used here. A dynamic array is reinitialized with Redim; the dimension cannot be changed. Two-dimensional to three-dimensional is not possible. If Erase is used on a dynamic array, you can't see anything, absolutely nothing, because a dynamic array only exists while the program is running. That's why you can't set it to zero! Erase frees up the array's memory space again; that doesn't work with static arrays. Redim: Is a combination of Erase and Dim. Without Redim, you would first have to erase a dynamic array with Erase and then reinitialize it with Dim. RE: REDIM takes more resources than DIM? - aurel - 07-17-2024 o2 fan..that would be me well i am not sure what static array is in qb64 and i don't have such a thing in o2 but o2 have static type of any variables which are good options as local variable inside functions. REDIM as such should as the name says RE-dimensioned existing array if REDIM arr(100) to arr(1000) just allocate new space for keeping existing data in first 100 elements then is fine, but if reset whole array then is fine to i don't know what qb64 internaly do with it. and this is just my observation... RE: REDIM takes more resources than DIM? - aurel - 07-17-2024 Quote:because a dynamic array only exists while the program is runningexcuse me @Kernel but that is kind of funny of course that array exist in memory when program running RE: REDIM takes more resources than DIM? - Dimster - 07-17-2024 I agree with you Kernelpanic, it's got to be trying when it appears we are beating a dead horse, but I do have problems with understanding the nuances of what goes into making a word in a programming language work and ReDim is one which does have me scratching my head. As you say it works with ERASE, which seems to wipe out the existence of the array itself. If its completely erased, then why would ReDim not also be able to resurrect a new name for the array? I surmise, some part of the original array (ie the name) must be saved when when you use ReDim. ERASE with a Dimmed array and that array is completely gone, name and all. Correct? So the only other use for ReDim, if you are not using it to expand your array with _Preserve, would be to completely wipe out the data of the array and start again to fill the same array with the same number of elements. ( ie saving the name of the array and number of elements). Not sure if that is any more efficient than For x = 1 to 50:Array(x)=0:Next |