Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REDIM, TYPE, and STRING Woes
#11
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!!!
b = b + ...
Reply
#12
(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.

Supposedly the numbers and fixed strings were fixed according to Luke if I recall but variable length strings had to initilized to "" otherwise they pick up garbage from the string pointers to uncleared meomory, something like that.

@TerryRichie could it be possible you were assuming new variable length strings were "" after a ReDim _Preserve ?

Perhaps also, whatever was fixed back when Luke checked it became unfixed with all the updates made since, like with assumed 0 of new integers created with ReDim _preserve?

I will write some test code...

I just posted a controller library in the library section. If you change the "Name AS STRING * 20" in "TYPE TYPE__SLOT" to "Name AS STRING" in the CONTROLLER.BI file you'll see the errors start to happen.

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.
b = b + ...
Reply
#13
(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.

So if you save to file a UDT it must be like the old days with fixed string lengths only!!!


Another clarification Tongue 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.
Reply
#14
(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.

So if you save to file a UDT it must be like the old days with fixed string lengths only!!!


Another clarification Tongue 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.

Save to a second file (say *.vlsd for variable length string data) and only have the main file store offset + size.  Wink
Reply
#15
(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.  Wink

I don't personally consider that a viable fix because writing UDTs to a file shouldn't result in other files being created Tongue 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 + size` entries, and we don't know where they all are.


The GitHub issue for the redim thing is here.
Reply
#16
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.  Tongue

[Image: Rem-Dynamic-2023-04-13.jpg]
Reply
#17
(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.
The storage space is only requested at runtime; see the thread about static and dynamic arrays.

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 `ReDim` from 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 `Dim` are treated the same as those created with `ReDim`.
Reply




Users browsing this thread: 9 Guest(s)