Results 1 to 6 of 6

Thread: Long-as pointers, is problem?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171

    Long-as pointers, is problem?

    Could the use of Long as Pointers - especially stringpointers - be a problem?

    Uses "Console"
    
    $Mousewheel = "MouseWheel" : %MouseWheel = StrPtr($MouseWheel)
    $MouseMove  = "MouseMove" : %MouseMove = StrPtr($MouseMove)
    
    Long myMessage = %MouseWheel
    
    Printl peek$(myMessage, strptrLen(myMessage)) 
    
    WaitKey
    
    works so far. But could it be a problem if a Pointer exceeds &H7FFFFFFF ? Or will stringpointers never do that?
    Last edited by ReneMiner; 29-05-2013 at 14:37.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Rene,

    you have the ability to find thinBasic keywords that even I do not remember to have developed

    Where memory is allocated is on the hands of the OS Kernel. The precise location where the memory is allocated is not known in advance.

    In LONG variables the first bit is used for the sign but when you store a pointer into a LONG, the sign has no meaning, it is just a number stored into a 4 byte.
    When such data is passed to a function expecting a pointer, the first bit is not used as sign and all is interpreted as a DWORD.

    So, in thinBasic use LONG and DWORD as interchangeable when storing a pointer.
    Important is not to make any calculation using LONG storing pointers otherwise it is better to use DWORD.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    On 32 Bit OS the addresses of virtual memory (in userspace not OS kernalspace) are never 32 bit.
    That means you can ignore the sign bit of LONG (it's never "1")

    For pointer calculation i would prefer DWORD as pointer type.

    Joshy
    (Sorry about my bad English.)

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    Yes, I would recommend/prefer Dwords too, but the constants are Longs by default. Since I use them absolute and do not calculate with them and because Eros says it's ok, I'll make my "constant string-enumerations" like this now using Longs.
    Just for interest: is there a way to make some Dword-constants?
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    Quote Originally Posted by ReneMiner View Post
    Just for interest: is there a way to make some Dword-constants?
    You can do it like this:
    Const MyConstant As DWord = 5
    
    ...or like this:
    %myConstant = 5 AS DWORD
    

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    Great- that means I can play on the safe side now
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Pointers...
    By matthew in forum TBGL General
    Replies: 5
    Last Post: 09-05-2013, 13:43
  2. I wonder how long it takes to make an object.
    By kryton9 in forum Shout Box Area
    Replies: 0
    Last Post: 26-06-2011, 07:32
  3. Function pointers?
    By MouseTrap in forum thinBasic General
    Replies: 2
    Last Post: 18-02-2009, 21:35
  4. missing info on pointers
    By jack in forum Help Material
    Replies: 1
    Last Post: 01-01-2009, 15:22
  5. Pointers and dereferenciation
    By ErosOlmi in forum thinBasic vaporware
    Replies: 7
    Last Post: 26-04-2007, 12:46

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
  •