Author Topic: Brief Review of O2 string types  (Read 2778 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3691
    • Oxygen Basic
Brief Review of O2 string types
« on: September 25, 2011, 01:07:02 PM »
I hope this clarifies all the string types defined in O2 core.

zstring / asciiz / char
Indirection level 0
Character width 1
Length determined by null terminator byte
Garbage collection not required

zstring2 / wchar
Indirection level 0
Character width 2
Length determined by 2 null terminator bytes
Garbage collection not required

bstring
Indirection level 1
Character width 1
Length given by 4 byte integer immediately before byte content
Also terminated by 2 null bytes
Garbage collection required

bstring2
Indirection level 1
Character width 2
Length (in bytes) given by 4 byte integer immediately before byte content
Also terminated by 2 null bytes
Garbage collection required

string
Indirection level 2  (1 when passed byval as a parameter)
Character width = 1
Length given by 4 byte integer immediately before byte content
Also terminated by 2 null bytes
Garbage collection automatic

wstring
Indirection level 2 (1 when passed byval as a parameter)
Character width 2
Length given by 4 byte integer immediately before byte content
Also terminated by 2 null bytes
Garbage collection automatic

I have a little more work to do on wide strings (wstring and wchar)

Charles




« Last Edit: September 25, 2011, 01:08:36 PM by Charles Pegge »

Aurel

  • Guest
Re: Brief Review of O2 string types
« Reply #1 on: September 25, 2011, 01:13:14 PM »
Thanks Charles....
Ufff i will stay with string... ::)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3691
    • Oxygen Basic
Re: Brief Review of O2 string types
« Reply #2 on: September 25, 2011, 01:34:05 PM »

I can honestly say I did not invent any of them :). The nearest equivalent to a string is the PowerBasic string which is based on the bstring which was originally developed by Microsoft for OLE and COM.

Zstring / char is the ubiquitous null-terminated string used in C.

Charles

efgee

  • Full Member
  • ***
  • Posts: 172
Re: Brief Review of O2 string types
« Reply #3 on: October 06, 2011, 10:24:57 AM »
Charles,
is the string really terminated by 2 zero bytes?
(Character width 1)

Peter

  • Full Member
  • ***
  • Posts: 161
Re: Brief Review of O2 string types
« Reply #4 on: October 06, 2011, 11:00:59 AM »
Hi efgee,

Quote
is the string really terminated by 2 zero bytes?

yes, I think

Code: [Select]
string s= "HELLO"
byte bVar, sys x

mov edi,*s
For x=0 to 6
mov ecx,x
mov al,[edi+ecx]
mov bVar ,al
pushad
print bVar + " = " + chr(bVar)
popad
next
« Last Edit: October 06, 2011, 11:05:53 AM by peter »

efgee

  • Full Member
  • ***
  • Posts: 172
Re: Brief Review of O2 string types
« Reply #5 on: October 06, 2011, 11:39:21 AM »
maybe it has 4:

Code: [Select]
string s= "HELLO"
byte bVar, sys x

mov edi,*s

For x=0 to 8
    mov ecx,x
    mov al,[edi+ecx]
    mov bVar ,al
    pushad
    print bVar + " = " + chr(bVar)
    popad
next

 ;D

Peter

  • Full Member
  • ***
  • Posts: 161
Re: Brief Review of O2 string types
« Reply #6 on: October 06, 2011, 11:58:50 AM »
*lol*

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3691
    • Oxygen Basic
Re: Brief Review of O2 string types
« Reply #7 on: October 06, 2011, 02:41:19 PM »
Hmm..

Microsoft says 2 null wide characters here:

http://msdn.microsoft.com/en-us/library/ms221069(v=vs.85).aspx

but here it says only one null byte here:

http://msdn.microsoft.com/en-us/library/aa910605.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/ms221637(v=vs.85).aspx

but I use this function for allocating all string/wstring/bstring space, and no trouble with COM and other unicode system calls so far.


I terminate string literals with 2 null bytes.

Charles

John

  • Hero Member
  • *****
  • Posts: 3150

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3691
    • Oxygen Basic
Re: Brief Review of O2 string types
« Reply #9 on: October 07, 2011, 06:56:08 PM »

The added workload with Basic strings is automatic garbage collection. String expressions which contain string functions generate temporary strings.

These strings have to be logged with the garbage collector for deletion at the end of the current Basic statement.

Since string functions may call other string functions, all of this has to work recursively.

Similarly local strings must be deleted at the end of a procedure, and static & global strings must be deleted at the end of the program.


And of course every time a string variable is assigned new content the original allocation has to be deleted first.

Charles