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) |
RE: REDIM takes more resources than DIM? - Kernelpanic - 07-17-2024 (07-17-2024, 12:49 PM)aurel Wrote:Yes, it's not so easy to make something understandable this.Quote:because a dynamic array only exists while the program is runningexcuse me @Kernel but that is kind of funny The lifespan of static variables or arrays corresponds to that of the program module in which they were defined. They cannot really be deleted. With Erase, all array elements are only initialized with zero. The memory space of dynamic arrays, on the other hand, is only acquired at runtime when a declaration is made in the program. The Erase command enables the occupied memory space to be released, when the array is no longer needed. RE: REDIM takes more resources than DIM? - luke - 07-17-2024 (07-17-2024, 09:16 AM)SMcNeill Wrote: May also be an issue with having to reset array values to 0.This was a bug that will be fixed in the next release. RE: REDIM takes more resources than DIM? - Kernelpanic - 07-17-2024 Quote:If its completely erased, then why would ReDim not also be able to resurrect a new name for the array?@Dimster, it's OK! It took me a while to understand that too; I hope so. Deleting with Erase only refers to the memory location of a declared array. Example: twoDimfield. If you now enter: ReDim threeDimfield, what is that supposed to do? The array threeDimfield wasn't even declared. Code: (Select All)
RE: REDIM takes more resources than DIM? - vince - 07-17-2024 in some other languages, static arrays are allocated in stack space while dynamic in heap space, so there might be some performance hit in exchange for more available space no idea what QB64PE resolves it to, though RE: REDIM takes more resources than DIM? - bplus - 07-17-2024 (07-17-2024, 01:36 PM)luke Wrote:(07-17-2024, 09:16 AM)SMcNeill Wrote: May also be an issue with having to reset array values to 0.This was a bug that will be fixed in the next release. I seem to recall it being fixed once at least for number in UDT's but varaible length strings messed things up. @Luke didn't you once say, I forget which forum, it doesn't matter if DIM everything or REDIM everything. Because from that I experimented with REDIM for everything, no problems! (until the extra 2 characters became tiresome and REDIM looked odd for plain variables). RE: REDIM takes more resources than DIM? - Pete - 07-17-2024 (07-17-2024, 02:10 PM)vince Wrote: in some other languages, static arrays are allocated in stack space while dynamic in heap space, so there might be some performance hit in exchange for more available space I swear I can recall the need to make all my arrays in QuickBASIC to get my programs to run. STATIC arrays used up too much memory, probably from the stack space. You could use the CLEAR command with parameters to set stack space and memory allocation ratios, to some degree. I always needed more stack space. Life was so much harder then, 20 years ago... Pete RE: REDIM takes more resources than DIM? - Kernelpanic - 07-17-2024 (07-17-2024, 02:10 PM)vince Wrote: in some other languages, static arrays are allocated in stack space while dynamic in heap space, so there might be some performance hit in exchange for more available space"quickbasic" had listed two books for download: https://qb64phoenix.com/forum/showthread.php?tid=2472&page=2 I have Book 2: QBasic programmers reference in German. The book is very good! What is discussed here starts on page 165, Erase. It also covers what is put on the heap and what is not, and so on. The book takes into account the then newest and last version of QBasic 1.1, which is newer than QuickBasic 4.5. - QBasic and QuickBasic are the same, but you cannot create exe files with QBasic. RE: REDIM takes more resources than DIM? - DSMan195276 - 07-17-2024 QB64 currently allocates both regular and dynamic arrays at runtime and on the heap (never on the stack). As far as QB64 programs are concerned this distinction doesn't matter, but it does mean that if you use `ReDim` to initially declare an array (and do not resize it later) then it's functionally no different from one declared via `Dim`. I'm pretty confident this is what Luke was getting at if/when he mentioned that you could replace `Dim` with `ReDim` with no penalty. RE: REDIM takes more resources than DIM? - Pete - 07-17-2024 But it's always hard to see what luke is getting at, because he's forever joking around. Pete RE: REDIM takes more resources than DIM? - aurel - 07-17-2024 My point was if we need to increase array size we should use REDIM ..right ? so DIM arr(100) REDIM arr(1000) that is only useful if we don't know what size we need..right? so if we have loop ..for example which require more space then REDIM in my own programs i never use REDIM i use fixed size. but that is me .. |