Announcement

Collapse
No announcement yet.

32-bit Pointers & Strings

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 32-bit Pointers & Strings

    Actually, this is a 2-part question:

    1. How does PB store strings? The reason I ask is that when looking at a character in a string use a 32-bit BYTE PTR I get a different value than when using the ASC function. For example:

    DEFINT A - Z
    DIM WorkPtr AS BYTE PTR
    I = 10
    DIM Work$(1 TO 10)

    WorkPtr = VARPTR32(Work$(1))
    Work$(1) = "HELLO"
    L = ASC(Work$(1),1)
    Z = @WorkPtr

    END

    L and Z will have different values.

    2. Why does program execution time increase with the addition of variables in a PUBLIC list, even if the variables are not used?
    Walt Decker

  • #2
    Answer to question #1: VARPTR points to the "string descriptor", which is a structure that is used interally by PowerBASIC. Use STRPTR to get a pointer to the actual string. See the VARPTR and STRPTR entries in the Help File for more information.

    -- Eric

    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited May 21, 2000).]
    "Not my circus, not my monkeys."

    Comment


    • #3
      Thank you Eric. But you've given me an option, not an answer.

      STRPTR with PEEK will give me the same as ASC, and STRPTR with PEEK$ will produce "H". Using VARPTR32 with a variable dimed as a string pointer will also give me "H". Since PEEK will return a value of 76, VARPTR32 with a variable dimed as a BYTE pointer should also return a value of 76, but it doesn't.

      So, the question still stands. How does PB store strings?

      ------------------
      Walt Decker

      Comment


      • #4
        I've told you everything I know. The basic answer that PB support has always given in the past is (to paraphrase)...

        "The storage technique is proprietary, primarily because we (meaning PB, Inc.) reserve the right to change it from version to version of the compiler. So you should not attempt to use the string descriptor directly in any way."

        That being said, somebody from PB may or may not be able to add additional information to this thread...

        -- Eric

        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>

        "Not my circus, not my monkeys."

        Comment


        • #5
          Eric's reply is correct. The answer to your question lies in the difference between STRPTR/STRPTR32 and VARPTR/VARPTR32 when it comes to dynamic strings.

          The next thing to be aware of is the difference is between a STRING PTR and STRPTR. They can be confusing, but the documentation should explain the differences for you.

          The following shows the right way to use some of these types of pointers:
          Code:
          dim a as string
          dim b as string ptr
          dim c as byte ptr
          a = "Hello"
          b = varptr32(a)
          c = strptr32(a)
          print a, @b, @c, CHR$(@c)
           
          Result:
          Hello         Hello          72           H
          I'm not aware of any information that could provide an answer to [your original] Question #2. To save some time, can you post some code that demonstrates the speed difference, and I'll look into it for you.


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Thank you, Lance. Actually, the PB code I sent support for the BYVAL problem demonstrates the time difference. By removing the PUBLIC statements that the snippet doesn't need to execute, that code reads something like 80Mb in about 5 + minutes. Adding the PUBLICs that the entire code needs, execution time increases to over 17 minutes (PDS is actually faster). I'll send support both codes.

            ------------------
            Walt Decker

            Comment

            Working...
            X