Already a Member? Join your peers on the Internet's largest technical computer professional community. It's easy to join and it's free. Register now while it's still free! Already a member? Close this window and log in. Join Us Close. Join Tek-Tips Forums! Join Us! By joining you are opting in to receive e-mail.
Promoting, selling, recruiting, coursework and thesis posting is forbidden. Students Click Here. But if you use ByRef, will it change? ByVal means that the procedure is not allowed to change the value. Things get tricky when you're talking about simple objects vs. The above rules apply for variables of type int, string, bool, etc.
The "ByVal" says that the DomDocument after the procedure is called will be the same one that was passed in. However, inside the procedure, the contents of the Xml document could be changed, and those changes would be visible outside the procedure. This pseudo-code illustrates this. In Visual Basic. NET, the As Any keyword is no longer supported. To ensure type safety, you must specifically declare the data type of all arguments and return values.
Determine where the declared function is being used in your code and what data type is being passed. If all occurrences use the same data type as a parameter, change the declaration to include the specific data type instead of As Any. If you need to support multiple data types, overload the function declaration for each data type.
The called API procedure inside of Shell What's a bit confusing is that the object is actually passed ByRef in the theoretical sense. A new object isn't instantiated, and the API call be will operating on the same object that was originally instantiated by VB6.
Now, a bit about strings particularly variable length strings. I'll still stay away from strings in API calls, because there's still another level of complexity in those cases. However, just within VB6, strings are rather easily aliased just as objects are aliased. For instance Now, strings variables just like object variables are pointers-to-pointers-to-TheData.
And that is the fundamental difference between VarPtr and StrPtr when dealing with strings. It's the same relationship that VarPtr and ObjPtr have. VarPtr points to the second-level pionter, and StrPtr returns a pointer from that second-level-pointer that points directly at the string.
This comes in particularly handy for strings because the VB6 garbage collector may move strings around in memory. If there wasn't a pointer-to-a-pointer, the garbage collector would somehow need to find all aliased versions of a string to move it in memory. However, with this pointer-to-a-pointer scheme, the garbage collector just needs to change the second-level-pointer and everything is good to go.
I know this is verbose, but maybe it's worth it to some. My contemporary VB6 project is approaching 1, modules. To all, peace and happiness. Originally Posted by Elroy This comes in particularly handy for strings because the VB6 garbage collector may move strings around in memory.
This part is a bit dubious as there is no GC in VB6. Whatever caching is happening is due to COM string handling and it's aggresiveness is controlled by OS settings. Whatever string aliasing is happening it's always on the stack. For instance if the argument is object reference and in the routine you Set the variant to Nothing the callers variable must be affected. Here's an interesting edge case. When you pass an object via ParamArray and use For Each to iterate. I think the confusion here is that - VB6 automatically allocates new BSTR's whenever referencing constants Or variables initialized to constants or fixed strings.
Not the work of a GC. BTW, although it quite clearly but i think that it need to clarify when you pass an object variable as ByVal it calls AddRef method twice - before calling and inside the procedure. Correspondingly it calls Release method 2 times too.
Originally Posted by The trick BTW, although it quite clearly but i think that it need to clarify when you pass an object variable as ByVal it calls AddRef method twice - before calling and inside the procedure. Yes, that seems to be the case, just did some tests -- quite ineffective impl but probably needed for edge cases.
Hi wqweto, Originally Posted by wqweto Whatever string aliasing is happening it's always on the stack. You actually could have string aliasing at module or global level but it would be dubious. You could use RtlMoveMemory to get it done, but you'd have to be very careful to put things back, or you'd cause a crash or have a memory leak.
Just saying, but I do understand your point. Also, I know you're somewhat correct about garbage collection, but I'm not at all convinced that strings don't move around. How else could VB6 do massive string manipulations with their sizes often changing and not run out of memory? I massage strings a great deal in my main application, and I've never had any memory problems.
I'll admit I'm not entirely familiar with the guts of VB6 at this level, but I'd be truly surprised if an unchanging string never gets moved in memory while other strings surrounding it are getting dramatically manipulated.
Or possibly it only does stuff while strings are being re-assigned. Again, that's pretty low-level VB6 stuff. Regarding calls to AddRef, I'm always amazed at what the count is for object references.
0コメント