REDIM, TYPE, and STRING Woes - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: REDIM, TYPE, and STRING Woes (/showthread.php?tid=1614) Pages:
1
2
|
RE: REDIM, TYPE, and STRING Woes - bplus - 04-12-2023 Oh yes, one more thing. UDT's have never been fixed for saving to file variable length strings. So if you save to file a UDT it must be like the old days with fixed string lengths only!!! RE: REDIM, TYPE, and STRING Woes - bplus - 04-12-2023 (04-12-2023, 04:00 PM)TerryRitchie Wrote:(04-12-2023, 03:50 PM)bplus Wrote: I've run into trouble using UDT's when I assume after a ReDim _Preserve that the new values are 0 or "" for numbers or strings. I scanned through code to see if you were either trying to do math on an assumed zeroed initialized variable or trying to save to file... couldn't even find the Type declaration, let alone seeing what you were doing with it. Sorry, too complicated for my patience today. Udate: OK found it in downloaded zip line 710 of BI but @TerryRichie you know better than I what you are doing with the Type items. RE: REDIM, TYPE, and STRING Woes - DSMan195276 - 04-12-2023 (04-12-2023, 05:59 PM)bplus Wrote: Oh yes, one more thing. UDT's have never been fixed for saving to file variable length strings. Another clarification This isn't really a bug, it's not supported and unlikely to ever be supported since it's not clear how to make it work in a sane way. As for the bug with Redim, I have it figured out. Basically what's going on is that with a normal Redim _Preserve the new memory (if any) is supposed to get zero'd, but when a Type contains a variable-length String that logic gets left out. We do already have logic to initialize all the new variable-length strings, so you should find the variable-length strings work and are always empty, but anything else in the Type will potentially contain garbage. I think this should be relatively easy to fix, I'll make a GitHub issue for it. RE: REDIM, TYPE, and STRING Woes - SMcNeill - 04-12-2023 (04-12-2023, 10:14 PM)DSMan195276 Wrote:(04-12-2023, 05:59 PM)bplus Wrote: Oh yes, one more thing. UDT's have never been fixed for saving to file variable length strings. Save to a second file (say *.vlsd for variable length string data) and only have the main file store offset + size. RE: REDIM, TYPE, and STRING Woes - DSMan195276 - 04-12-2023 (04-12-2023, 10:20 PM)SMcNeill Wrote: Save to a second file (say *.vlsd for variable length string data) and only have the main file store offset + size. I don't personally consider that a viable fix because writing UDTs to a file shouldn't result in other files being created IMO it just creates too many potential problems. Storing them all in a single file also has separate issues because any reorganization of them would require modifying all the offset + sizeentries, and we don't know where they all are. The GitHub issue for the redim thing is here. RE: REDIM, TYPE, and STRING Woes - Kernelpanic - 04-12-2023 In the present case, the meta command "$Dynamic" should/could help. The $Dynamic metacommand is a compiler switch that causes the compiler to not reserve fixed memory space for arrays during compilation. The storage space is only requested at runtime; see the thread about static and dynamic arrays. Meta commands are to be specified as comments! I tried it once. . . but I would have to kneel in too hard now. RE: REDIM, TYPE, and STRING Woes - DSMan195276 - 04-13-2023 (04-12-2023, 11:48 PM)Kernelpanic Wrote: In the present case, the meta command "$Dynamic" should/could help. The $Dynamic metacommand is a compiler switch that causes the compiler to not reserve fixed memory space for arrays during compilation. In QB64 the $Dynamic metacommand doesn't actually do much. Both static and dynamic arrays are allocated at runtime, but static arrays have a flag set on them that prevents ReDimfrom working (it errors instead) and makes a handful of commands work slightly differently. When you use $Dynamic this flag isn't set so arrays created with Dimare treated the same as those created with ReDim. |