Page 4 of 12

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Mon Jan 26, 2026 3:13 pm
by akee
Thanks Fred.

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Mon Jan 26, 2026 8:03 pm
by threedslider
BarryG wrote: Mon Jan 26, 2026 12:50 pm
User_Russian wrote: Mon Jan 26, 2026 11:28 amMessageRequester() - 267 KB.
Empty source file - 265 KB.
Let's compare that with PureBasic 5.73:

MessageRequester() - 4.50 KB.
Empty source file - 2 KB.

That's why I still use 5.73 for my private projects. ;) The old PureBasics were so lean and clean.
:shock:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 5:11 am
by DeanH
The change to string handling sounds similar to the old BSTR string type. Much faster to read records from a large SQLite database. Question: how is the length stored? Long? Quad? Another way? Does it limit the maximum length of a string?

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 7:14 am
by PrincieD
Wow! that sounds awesome Fred, so instead of reading a string for null termination - the length is already cached?

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 10:51 am
by Little John
PrincieD wrote: Tue Jan 27, 2026 7:14 am Wow! that sounds awesome Fred, so instead of reading a string for null termination - the length is already cached?
Yes, that is the case:
Fred wrote:All strings are now prefixed by their length (except the strings in DataSection). [...]
That means than all string operation will have instant length information resulting in faster operation as iterating byte by byte on the string to find the null terminated char is no more needed.
It's the way e.g. Turbo Basic did it already about 35 years ago. ;-)

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 11:39 am
by Fred
DeanH wrote: Tue Jan 27, 2026 5:11 am The change to string handling sounds similar to the old BSTR string type. Much faster to read records from a large SQLite database. Question: how is the length stored? Long? Quad? Another way? Does it limit the maximum length of a string?
It's an integer minus 1 bit (31 bit on x86, 63 bit on x64).

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 12:47 pm
by Matheos
Fred wrote: Tue Jan 27, 2026 11:39 am
DeanH wrote: Tue Jan 27, 2026 5:11 am The change to string handling sounds similar to the old BSTR string type. Much faster to read records from a large SQLite database. Question: how is the length stored? Long? Quad? Another way? Does it limit the maximum length of a string?
It's an integer minus 1 bit (31 bit on x86, 63 bit on x64).
I appreciate you said in the opening post that the terminating null is still retained, but could this possibly lead eventually to an ability to store x'00 in string values?

I support an application that provides independent string functions, written primarily to do this, although with performance objectives in mind also, so I'm keen to experiment further when I have chance and see if we can begin to take advantage of this change.

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 1:23 pm
by Fred
Theorically, you can put 0 in it. But it won't be officially supported for now (could evolve later but will be per command decision)

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 4:32 pm
by skywalk
Fred - did you consider making another string type?
Ex. Cstring for api, FastString for internal?

Or is the plan to have new string support all api calls with null terminated strings?

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 5:22 pm
by Fred
There is no plan to have an additional string for API call, as they are always null terminated. The only case when it needs an adjustment is when you use a string for output buffer using Space().

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 7:27 pm
by HeX0R
A probably easier method to recalc the length of the string, without any fancy additional procedures:

Code: Select all

PureBasicPath$ = Space(#MAX_PATH)
GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
Debug Len(PureBasicPath$)
PureBasicPath$ = PeekS(@PureBasicPath$)
Debug Len(PureBasicPath$)
Edit
oh god, my bad, Fred even mentioned that in the initial post :shock:
Using Win32 API with Space() for example will require an extra PeekS().

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 7:44 pm
by ChrisR
Or by using fryquez ResetStringLength procedure/macro: viewtopic.php?p=650721#p650721

Code: Select all

CompilerIf #PB_Compiler_Version >= 640
  Declare ResetStringLength(*s.Character)
  
  Procedure ResetStringLength(*s.Character)
    Protected *p.Integer = *s -SizeOf(Integer)
    *p\i = 0
    While *s\c
      *p\i + 1
      *s + SizeOf(Character)
    Wend
  EndProcedure
CompilerElse
  Macro ResetStringLength(s)
    ;
  EndMacro
CompilerEndIf

CompilerIf Not #PB_Compiler_Debugger
  OpenConsole("ResetStringLength")
  Start = ElapsedMilliseconds()
  For l = 0 To 5000000
    PureBasicPath$ = Space(#MAX_PATH)
    GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
    PureBasicPath$ = PeekS(@PureBasicPath$)
  Next
  PrintN("PeekS Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms")
  
  Start = ElapsedMilliseconds()
  For l = 0 To 5000000
    PureBasicPath$ = Space(#MAX_PATH)
    GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
    ResetStringLength(@PureBasicPath$)
  Next
  PrintN("ResetStringLength Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms")
  
  Delay(10000)
CompilerEndIf
;PeekS Len(61): 517 ms
;ResetStringLength Len(61): 350 ms

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 7:50 pm
by freak
ChrisR wrote: Tue Jan 27, 2026 7:44 pm Or by using fryquez ResetStringLength procedure/macro: viewtopic.php?p=650721#p650721

Code: Select all

CompilerIf #PB_Compiler_Version >= 640
  Declare ResetStringLength(*s.Character)
  
  Procedure ResetStringLength(*s.Character)
    Protected *p.Integer = *s -SizeOf(Integer)
    *p\i = 0
    While *s\c
      *p\i + 1
      *s + SizeOf(Character)
    Wend
  EndProcedure
CompilerElse
  Macro ResetStringLength(s)
    ;
  EndMacro
CompilerEndIf

CompilerIf Not #PB_Compiler_Debugger
  OpenConsole("ResetStringLength")
  Start = ElapsedMilliseconds()
  For l = 0 To 5000000
    PureBasicPath$ = Space(#MAX_PATH)
    GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
    PureBasicPath$ = PeekS(@PureBasicPath$)
  Next
  PrintN("PeekS Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms")
  
  Start = ElapsedMilliseconds()
  For l = 0 To 5000000
    PureBasicPath$ = Space(#MAX_PATH)
    GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
    ResetStringLength(@PureBasicPath$)
  Next
  PrintN("ResetStringLength Len(" + Str(Len(PureBasicPath$)) + "): " + Str(ElapsedMilliseconds() - Start) + " ms")
  
  Delay(10000)
CompilerEndIf
;PeekS Len(61): 517 ms
;ResetStringLength Len(61): 350 ms
Just don't act surprised when that code breaks in the future because you are clearly messing with internals here. There is such a thing as over-optimizing.

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 8:20 pm
by mk-soft
The test on NIL (null pointer) is missing

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Posted: Tue Jan 27, 2026 8:56 pm
by diceman
Fred wrote: Fri Jan 23, 2026 10:47 amBasically if you patch a string by putting a zero in it, the Len() function will be wrong, and the concat functions will fail. You will need to use PeekS() for this.
Please, for really stupid people like me, can you explain in layman's terms what that actually means? :o
Kinda afraid to install the patch, as I am doing a lot of String Operations, and seeing anything break that worked before in my 65k lines-project, would just cause unneccessary stress to me, lol, thanks.

- What does "patching a string by putting a zero in it" even mean?
- What are concat functions?
- An snippet of a thing that worked before, and after the patch has to be done with PeekS (never used that one either) would be great.