• Welcome to Jose's Read Only Forum 2023.
 

O2: bstring

Started by José Roca, September 09, 2013, 04:12:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

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

The main visible difference is the indirection level, but I'm not sure what it means. When is it advisable to use bstring/bstring2 instead of string/wstring?

TIA

Charles Pegge

OxygenBasic strings are very similar to PowerBasic strings. They are pointers to Bstrings/OLE strings (which are in turn, pointers to blocks of characters as described above )

The extra level of indirection/pointering is used to located an entry in one of the garbage collectors lists. When the string loses its scope, the garbage collector will SysFreeString all the strings on one of its lists.

Internally, there are 3 types of lists:

Temp: for strings used as intermediates in an expression

Local: for strings used in a procedure

Global: for all static and global strings. These are collected when the program or DLL terminates.

string and wstring are the only ones which are automatically garbage collected.

Theo Gottwald

Can we have 64 bit strings with 64 bit LENGTH Charles?
I have seen in PureBasic x64 that the Strings are only 32 bit lenght.

José Roca

No. You would need to roll your own routines to manage them, and they will be incompatible with any other language and with the operating system.

José Roca

Quote
string and wstring are the only ones which are automatically garbage collected.

My main interest is to known if I can use a wstring to call a function or COM method that expects a bstring.

Charles Pegge

Yes, wstrings and bstring2 are handled transparently. Also, inter-conversion between string types is automatic.

With regard to 64bit strings, I can't find any clear advice on allocating >4GB memory blocks, on the web. Which OS calls would you use?

Theo Gottwald

#6