Results 1 to 13 of 13

Thread: Pointers (Dynamic Memory)

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Arrow Pointers (Dynamic Memory)

    I am designing a tree structure...
    How can I use pointers? I mean, no mouse pointers but pointers as:

    Something -> Anything

    I can't find a way to do it... Could you please help me?
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Does this mean I have to use a variable as a pointer?

    Isn't there another way?
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  4. #4

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    How can this be used?

    VB Code:
    1. ObjPtr
    2. VarPtr
    3. StrPtr
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  5. #5
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    ObjPtr(ClassName) returns the pointer to a COM+ class.
    VarPtr(x) returns the pointer to a variable.
    StrPtr(strName) returns the pointer to a string.

    In order to use these effectively, you will need to use the API MoveMemory in order to move these pointers to a custom UDT for you to use. Then, after you are done, you must move them back.

    NOTE that this means that every time you change a linked list's node, you need to call MoveMemory again to move the mew pointer specified in "pNext As Long."

    MoveMemory is defined as the following:

    VB Code:
    1. Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

    If you truly want to set the pCur UDT to POINT to a node in the list like a true linked list would do, you'll have to define your own API function to do so. This isn't so hard, and this may be much easier than moving the memory block back and forth.

    Alternatively, you can use classes. By using the Set keyword, you can set one class to EQUAL another.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  6. #6

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Talking Er...

    I am sorry to bug you, MicroBasic... But could you give me an example?

    I am really new at this. Let's say this is an opportunity area for me... Right now I am trying to write my own type named "Binary Tree"
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  7. #7
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Well, to make your custom API, you will have to make a C++ standard DLL that exports a function that will set one pointer equal to another.

    To use ovememory, you can do something like:

    VB Code:
    1. MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE)
    2.  
    3. [code to work with pCur]
    4. ' Some Code
    5. ' Some Other Code
    6. [/code to work with pCur]
    7.  
    8. MoveMemory pCur, ByVal Listx.pNext, Len(MYTYPE)

    NOE: This is a very crude code. You'll have to refine it on your own.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  8. #8

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Smile Thanks!

    I can see so but I still don't understand it 100%

    Forgive me for insisting but if I don't understand I know I will end up asking again, so I would like to grasp completely the concept.


    VB Code:
    1. 'Is pCur the Pointer?
    2.  
    3. MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE)
    4. 'Is this like "New(Pointer)"?
    5.  
    6. 'What is Listx.pNext?
    7. 'What is MYTYPE?
    8.  
    9. [code to work with pCur]
    10. ' Some Code
    11. ' Some Other Code
    12.  
    13. 'In here do you mean I am working with the pointer?
    14. 'Could this be like x^.name = 'Me'?
    15.  
    16. [/code to work with pCur]
    17.  
    18. MoveMemory pCur, ByVal Listx.pNext, Len(MYTYPE)
    19. 'Is this like "Dispose(Pointer)"?
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  9. #9
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    This is just a sample.

    VB Code:
    1. MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE)

    This code moves whatever pointer is in Listx.pNext to pCur.


    Now you should read data in Cur and do whatever you want with the pointer.

    VB Code:
    1. MoveMemory pCur, ByVal Listx.pNext, Len(MYTYPE)

    This code moves whatever in in pCur back into the pointer.

    The custom API method is much easier, though.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  10. #10

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Red face Oh... :D

    And which might be that custom API?

    *Laughs out loudly*
    I would hate to reply to myself being so pesky.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  11. #11
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Basically make your own DLL in VC++ and export a function that assigns a pointer to another, like:

    Code:
    extern "C" _declspec(dllexport) long CALLBACK repoint(void *a, void *b)
    {
        if(b != NULL)
            delete b;
        b = a;
    }
    
    extern "C" _declspec(dllexport) long CALLBACK mknew(void *a, long bytes)
    {
        b = new char[bytes];
    }
    Now you can use that custom API to point one pointer to another or to assign one pointer to a blank memory space.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  12. #12

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Talking Oops...

    It is I don't have VC++ since I lack space... So what can I do?
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  13. #13

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Er... Did you forget about me? ::
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

Posting Permissions

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



Click Here to Expand Forum to Full Width