Theos PowerBasic Museum 2017

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: José Roca on September 09, 2013, 04:12:19 PM

Title: O2: bstring
Post by: José Roca on September 09, 2013, 04:12:19 PM
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
Title: Re: O2: bstring
Post by: Charles Pegge on September 09, 2013, 05:06:57 PM
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.
Title: Re: O2: bstring
Post by: Theo Gottwald on September 09, 2013, 09:26:35 PM
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.
Title: Re: O2: bstring
Post by: José Roca on September 09, 2013, 09:49:57 PM
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.
Title: Re: O2: bstring
Post by: José Roca on September 09, 2013, 09:53:46 PM
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.
Title: Re: O2: bstring
Post by: Charles Pegge on September 10, 2013, 04:25:32 AM
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?
Title: Re: O2: bstring
Post by: Theo Gottwald on September 10, 2013, 06:34:44 AM
Fundamentals of Garbage Collection MSDN (http://msdn.microsoft.com/en-us/library/ee787088.aspx)

Here is an discussion on that topic:

WinAPI: Allocating large Memory chunks (http://stackoverflow.com/questions/181050/can-you-allocate-a-very-large-single-chunk-of-memory-4gb-in-c-or-c)

Ist hat true?
Somebody says that the total Memory of one running Application can not exceed 8 GB (http://blogs.msdn.com/b/tom/archive/2008/04/10/chat-question-memory-limits-for-32-bit-and-64-bit-processes.aspx) ?

Then this would possibly the limit.

MSDN WindowsOS Memory Limits (http://blogs.msdn.com/b/tom/archive/2008/04/10/chat-question-memory-limits-for-32-bit-and-64-bit-processes.aspx)

Process Memory Limit on x64 (http://stackoverflow.com/questions/2399162/process-memory-limit-of-64-bit-process)

Windows Memory Limits (http://173.194.35.151/url?sa=t&rct=j&q=memory%20limits%20msdn%2064&source=web&cd=8&cad=rja&ved=0CGMQFjAH&url=http%3A%2F%2Foracle.tistory.com%2Fattachment%2Fcfile23.uf%40133C173E4D25480A1C71D4.pdf&ei=lKEuUur9OIbbswb79IEo&usg=AFQjCNE7g02uaOXrUuk-jFpmf0sTCpPLmw&bvm=bv.51773540,d.Yms)