Announcement

Collapse
No announcement yet.

Gpf

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

  • Arthur Gomide
    replied
    Bob,

    I think it would be very helpful to include these comments on the clause "REDIM PRESERVE" in the Help file.

    Best Regards,

    Leave a comment:


  • Bob Zale
    replied
    In a REDIM PRESERVE:

    1- The array descriptor never moves.
    2- The string data never moves.
    3- The string handles which point to the string data never change.
    4- The block of memory where the string handles are stored may change if the block can not be expanded to the new size.
    5- VARPTR() of an array element may change.
    6- STRPTR() of an array element will not change.

    Bob Zale
    PowerBASIC Inc.

    Leave a comment:


  • Michael Mattias
    replied
    Originally posted by Gus del Solar View Post
    I know redim moves the actual string data, but I'm using VARPTR and supossed (evidently wrong) handles was fixed.
    Anyway, just refreshing the pointers after any redim did the trick.
    Actually, the string *data* do not move at all during a REDIM PRESERVE of a STRING array...i.e, the STRPTR would still be valid. In this case the STRPTR is useless (you need the VARPTR) but it would remain valid.

    (I think that's correct: it wouldn't make sense to rebuild all the strings when not necessary).

    But since it's working correctly now, do you really care?

    MCM

    Leave a comment:


  • Guest's Avatar
    Guest replied
    I know redim moves the actual string data, but I'm using VARPTR and supossed (evidently wrong) handles was fixed.
    Anyway, just refreshing the pointers after any redim did the trick.
    This thing flyes now

    Thank you both.

    Leave a comment:


  • Michael Mattias
    replied
    Originally posted by Gus del Solar View Post
    You right.

    It is not supossed string handles doesn't moves?

    Thank you.
    REDIM causes the block of memory allocated to hold the array elements to move, so the address of the string handle (the "STRING PTR") changes on REDIM.

    MCM

    Leave a comment:


  • Guest's Avatar
    Guest replied
    You right.

    It is not supossed string handles doesn't moves?

    Thank you.

    Leave a comment:


  • Michael Mattias
    replied
    ARRAY INSERT won't change the address of element zero, but REDIM will for sure.

    i.e, Kev's fix will work.

    Leave a comment:


  • Kev Peel
    replied
    By glancing at the code I see that your REDIM PRESERVE and ARRAY INSERT statements may be reallocating the array data, making the previously obtained pointer invalid. Try obtaining the names(0) pointer after the REDIM, to remedy.

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Gpf

    Gpf

    Hi all,

    Can someone please explain why this code gpf?
    Not always...just sometimes. I double checked
    not going beyond array bonds and the pointers > 0,
    ...same thing. I'm not using strptr(string) but varptr(string).
    I isolated this offending snippet. Actually, the type shown
    below has many other pointers, but just the string ptr gpf.
    The weird thing, it sometimes gpf when reading, others when
    trying to assign a string. There is something I'm doing wrong?

    Thanks in advance

    Gus

    Code:
    type main_type
       nstr as string ptr
       idx as long
    end type
    
    function mainthing() as long     '<- main entrance
      local mtp as main_type
      local pmtp as dword
      local names() as string
      redim names(512)
      mtp.nstr = varptr(names(0))
      mtp.idx = 3
      pmtp = varptr(mtp)
      
      
    ' then some processing...ie
      redim preserve names(ubound(names)+1)
      array insert names(), "this thing"
      '...
      names(28) = "this other guy"
    
    ' then a call to do some other processing
      dothings(pmst)
      '...
      '...
        
    end function
    
    function dothings(byval mtp as main_type ptr) as long
      local st as string
      st = "damngpf"
      @[email protected][@mtp.idx] = st   '<---THIS GPFs
      st =  @[email protected][@mtp.idx]  '<---THIS also GPFs
    
      @[email protected][1] = st   '<---THIS GPFs
      st =  @[email protected][1]  '<---THIS also GPFs!!!
    
    end function
Working...
X