Results 1 to 8 of 8

Thread: Freebasic Strings again

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    Freebasic Strings again

    This is a follow on from this thread http://community.thinbasic.com/index...;topicseen#new

    This is a question for Charles really.

    you said something about copying the string to/from bstr but couldnt that take a lot of time, the string lengths I am planning on working with could be very large or very small.

    Does FB have the ability to overlay arrays on top of my imported data.

    So if I had

    [code=freebasic]DIM input AS STRING

    TYPE mydata FIELD = 1
    buff( 0 to Len(input)) as ubyte
    END TYPE

    DIM mystring AS mydata AT STRPTR(input)
    [/code]

    I know i used cross between TB and FB but you get the idea.

    Any help would be useful.

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2

    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]

  3. #3
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    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.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  4. #4

    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:
    Attached Files Attached Files

  5. #5
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    160

    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.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  6. #6

    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

  7. #7

    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.

  8. #8
    I lost all of my own FreeBASIC thinCore stuff.
    However after some research i found out the BSTR / OLESTRING is in real only a pointer on UCHAR not WCHAR.
    #ifndef OLE2ANSI
    type OLECHAR as WCHAR
    #define OLESTR(s) wstr(s)
    #else
    type OLECHAR as byte
    #define OLESTR(s) s
    #endif
    
    type BSTR as OLECHAR ptr
    
    That means I can receive and transmit it as simple zstring ptr.
    DECLARE FUNCTION  thinBasic_ParseStringPtr ALIAS "thinBasic_ParseString" (byval pp as zstring ptr ptr) AS long
    
    Note: SysAllocStringByteLen()
    If you allocate and returns an BSTR from FreeBASIC DLL the memory will never be freed (exept the OS unload the DLL)

    Sorry if i'm wrong but all my current tests with zstring ptr as BSTR replacement works without any MPF. (Memory Protection Fault)

    Joshy
    Last edited by D.J.Peters; 20-05-2013 at 03:32.
    (Sorry about my bad English.)

Similar Threads

  1. FreeBasic strings
    By ErosOlmi in forum Module SDK (Freebasic version)
    Replies: 12
    Last Post: 21-11-2008, 08:28

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •