LoginLogin

Cost of CHKWHATEVS and the empty string

Root / Programming Questions / [.]

kldck_hulCreated:
Is doing CHKCALL or CHKLABEL an expensive operation? I imagine it looks in a table and comes back, no? Also, how expensive is a line like:
return ""
When does "" become the system-wide empty string?

The CHK functions can't be any more expensive than the overhead of actually using CALL or RESTORE, because those functions check first for exception handling. What's the "system-wide empty string"? This isn't like Java where strings are immutable. That will create a string of length 0 and return a reference to it, simple as that.

I don't use SmileBASIC, but I'd think it wouldn't be too expensive (or take a long time to run). If you did something like that in another language, it would be almost immediate. Never mind that the 3DS is a much slower ARM processor. It will still be pretty fast if you're looking in a table. If you'd like a benchmark for that, do this in a program. If I missed some new SB syntax, add it DIM X$(3) X$(0)="I like turtles" X$(1)="Hello, world!" X$(2)="I love SmileBASIC" FOR I=0 TO 2 IF X$(I)=="I love SmileBASIC" THEN PRINT "Worked!" NEXT

I was under the impression that the empty string always pointed to the same string... weird. Like strings were more of a functional list than arrays or something that wouldn't run well, I dunno. It would be neat if it didn't allocate an array until it had length If I define a string in PRG2 and return it to PRG0 from a COMMON DEF, is it the same the same string, or a copy?

It's the same string - though if it was defined as a local variable in PRG2 then that local reference is deleted and the only reference that remains is the returned one (which can then be assigned to a string variable in PRG0 - also not a copy). COPY does work on strings if you want to force a copy, though. Strings and arrays both work on the principle that they are deleted when no more references to them exist.