Re: Freebasic Strings again
Hi Mike,
FB does not appear to have an overlay mechanism like PB absolute arrays. But I did some tests and found FB does not mind passing anonymous pointers. So you can pass the pointer of one kind of data and receive it as the pointer to another kind of data. - which is almost as good as a simple overlay.
Of course passing data between TB and FB gives you greater opportunities to fudge the header declarations and pass the parameters byref instead of pointers byval.
[code=thinbasic]
'FreeBasic
'FB SUPPORTS ANONYMOUS POINTERS
dim as long a(100)
dim as any ptr p
p=varptr(a(0))
a(0)=65
sub fz(byval z as zstring ptr)
print *z
end sub
'These work:
asm
push [p]
call fz
end asm
fz p
[/code]
Re: Freebasic Strings again
Thanks for your help Charles very useful information.
Quote:
Originally Posted by Charles Pegge
Of course passing data between TB and FB gives you greater opportunities to fudge the header declarations and pass the parameters byref instead of pointers byval.
I dont quite understand what you mean (it could be me, I was awake for about 20 hours yesterday and my brain is off planet at the moment) so if you could talk very slowly I might understand.
1 Attachment(s)
Re: Freebasic Strings again
Mike,
2 Functions for sharing / passing / returning text string data between TB and an FB module. These are only suitable for strings that do not contain null bytes, because the passed data is assumed by FB to be a zstring ( though it is actually an ole BSTR).
thinBasic
[code=thinbasic]
'
'----------------------------------------------
'Module with string functions suitable for text
'==============================================
' sensitive to null byte as termintor character
uses "testm"
dim s as string
s="hello module!"
shareStringBuffer strptr(s)
msgbox 0,s
msgbox 0, returnString "Hello!"[/code]
FreeBasic
[code=thinbasic]
'
'
' fbc -dylib thinBasic_testm.bas
'
#include Once "thinCore.bi"
sub shareStringBuffer()
dim as long bz
dim as zstring ptr pz
thinBasic_ParseLong(bz) : pz=cast(zstring ptr,bz)
mid$(*pZ,1)="done: "
end sub
function returnString() as bstr
dim as double d
dim as bstr bz
dim as zstring ptr pz
dim s as string
d=thinBasic_ParseString(bz) : pz=cast(zstring ptr,bz)
s="Return: "+*pz
function=SysAllocStringByteLen ( strptr(s), len(s))
end function
FUNCTION LoadLocalSymbols Cdecl ALIAS "LoadLocalSymbols" (BYVAL sPath AS STRING) AS Long EXPORT
thinBasic_LoadSymbol ("shareStringBuffer", thinBasic_ReturnNone, @shareStringBuffer, thinBasic_ForceOverWrite)
thinBasic_LoadSymbol ("returnString", thinBasic_ReturnString, @returnString, thinBasic_ForceOverWrite)
FUNCTION = 0
END FUNCTION
Function UnLoadLocalSymbols Cdecl ALIAS "UnLoadLocalSymbols" (BYVAL sPath AS STRING) AS Long EXPORT
FUNCTION = 0
END FUNCTION
[/code]
Kit:
Re: Freebasic Strings again
Thanks again Charles but I will be passing data which will probably include null bytes so I think FB is too much hard work, Ive spent longer trying to get the data in FB and not done any work on actually processing the data.
I will use another option.
Thanks for your help.
Re: Freebasic Strings again
If you change your mind Mike, I can show you how to transfer string data efficiently. Byte transfers in Asm only take a few nanoseconds - say 100Mb per Second depending on RAM speed. Have you had any other obstacles with FB ?
Charles
Re: Freebasic Strings again
Mike, why couldn't you use an array of uBytes?
sounds to me you are using strings for non-string data.