|
-
Sep 12th, 2002, 04:50 PM
#1
Thread Starter
Frenzied Member
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
-
Sep 12th, 2002, 04:52 PM
#2
PowerPoster
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Sep 12th, 2002, 05:02 PM
#3
Thread Starter
Frenzied Member
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
-
Sep 12th, 2002, 05:10 PM
#4
Thread Starter
Frenzied Member
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
-
Sep 12th, 2002, 05:23 PM
#5
Frenzied Member
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:
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 .
-
Sep 12th, 2002, 07:29 PM
#6
Thread Starter
Frenzied Member
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
-
Sep 12th, 2002, 07:54 PM
#7
Frenzied Member
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:
MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE)
[code to work with pCur]
' Some Code
' Some Other Code
[/code to work with pCur]
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 .
-
Sep 12th, 2002, 08:00 PM
#8
Thread Starter
Frenzied Member
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:
'Is pCur the Pointer?
MoveMemory ByVal Listx.pNext, pCur, Len(MYTYPE)
'Is this like "New(Pointer)"?
'What is Listx.pNext?
'What is MYTYPE?
[code to work with pCur]
' Some Code
' Some Other Code
'In here do you mean I am working with the pointer?
'Could this be like x^.name = 'Me'?
[/code to work with pCur]
MoveMemory pCur, ByVal Listx.pNext, Len(MYTYPE)
'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
-
Sep 12th, 2002, 08:07 PM
#9
Frenzied Member
This is just a sample.
VB Code:
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:
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 .
-
Sep 12th, 2002, 08:13 PM
#10
Thread Starter
Frenzied Member
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
-
Sep 12th, 2002, 09:06 PM
#11
Frenzied Member
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 .
-
Sep 12th, 2002, 10:30 PM
#12
Thread Starter
Frenzied Member
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
-
Nov 3rd, 2002, 06:42 PM
#13
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|