ByVal vs ByRef when generating tree

I have a tree data structure in xml. I currently use ByVal and
recursion to draw the tree. My understanding is that each time I pass
the child node to the recursive function, it creates a copy of the
node containing items at the point and all subitems. I'm wondering it
it would make a lot of difference in memory usage if I pass the child
node by ref.
0
teddybear
11/15/2009 5:39:55 PM
scripting.vbscript 564 articles. 0 followers. Follow

2 Replies
915 Views

Similar Articles

[PageSpeed] 0

teddybear schrieb:
> I have a tree data structure in xml. I currently use ByVal and
> recursion to draw the tree. My understanding is that each time I pass
> the child node to the recursive function, it creates a copy of the
> node containing items at the point and all subitems. I'm wondering it
> it would make a lot of difference in memory usage if I pass the child
> node by ref.

In VBScript an object is *not* a contiguous area of memory holding
data, but a pointer/reference/handle giving indirect access to such data.
Copying an object (whether by assignment or by passing by value) is cheap,
but seldom (never ?) useful.

See:

   Dim sXML : sXML     = "<root><child>one</child></root>"
   Dim oXML : Set oXML = CreateObject( "MSXML2.DOMDocument" )
   oXML.loadXML sXML
   WScript.Echo 0, oXML.xml
   Dim ndChild : Set ndChild = oXML.documentElement.firstChild
   byRefXml ndChild
   WScript.Echo 1, ndChild.xml
   byValXml ndChild
   WScript.Echo 2, ndChild.xml
   byValValXml (ndChild)
   WScript.Echo 3, ndChild.xml

output:

=== XmlByRefVal: ByRef/ByVal for xml no
0 <root><child>one</child></root>

1 <child>two</child>
2 <child>three</child>
3 <child>four</child>
=== XmlByRefVal: 0 done (00:00:00) ====
0
ekkehard
11/15/2009 6:58:41 PM
teddybear schrieb:

> I have a tree data structure in xml. I currently use ByVal and
> recursion to draw the tree. My understanding is that each time I pass
> the child node to the recursive function, it creates a copy of the
> node containing items at the point and all subitems. I'm wondering it
> it would make a lot of difference in memory usage if I pass the child
> node by ref.


Afacis you cannot truly pass an object by value in VBScript.
Even if you denote 'ByVal' to the formal parameter:

   Function PassByVal (ByVal objectArg)

VBS will effectively still pass an reference to the original object.

All that's passed by value is the long variable, that holds the address
of the object. But there'll be no new instancing or even
cloning of member data in any way.

If you modify some of the objects data inside the body of the supposed
ByVal-function, the object data remains modified after having returned,
which clearly indicates that you worked on the same instance.

This makes a difference to languages that support true by-value-passing 
  - internally creating a shallow copy (memcopy) - as does C++.

See the listing below, that shows that ByVal or ByRef makes no
difference if the parameter is an object.
You get the same effect if you use test the mechanism on
ActiveX-objects instantiated by CreateObject
rather then VBScript class-objects.

If you need copies, you have to copy the data on your own - unless
your object already supports some kind of clone mechanism.


Christoph




set obj = new ByValTest
obj.Value = 10

wsh.echo "Outside any func:", obj.Value '10
ByValPassing obj
wsh.echo "Outside any func:", obj.Value 'now 11,
              'shold remain 10 if byval would create a cpy
ByRefPassing obj
wsh.echo "Outside any func:", obj.Value 'now 12

class ByValTest
   private valueData
   public property get Value : Value = valueData : end property
   public property let Value(dat) : valueData = dat : end property
end class

sub ByValPassing(ByVal objArg)
   objArg.Value = objArg.Value + 1
   wsh.echo "Inside byval-func:", objArg.Value
end sub

sub ByRefPassing(ByRef objArg)
   objArg.Value = objArg.Value + 1
   wsh.echo "Inside byref-func:", objArg.Value
end sub

0
Christoph
11/16/2009 10:30:44 PM
Reply:

Similar Artilces:

Upgrading to Money 2004 vs SLOW 2002
After reading several pages of questions, I'm worried about upgrading in general. It doesn't sound like Money 2004 is very stable. Money 2002 is doing ok for me but it's slow as a snail and I was hoping for some improvement. I've archived the old stuff out of my file and my computer is plenty fast. Any comments? Does 2004 work? Is it any faster than 2002? Or did they cram so much more stuff in that it's still slow? (And I mean Seriously Slow! I go surf while it's loading.) M04 does not seem appreciably different in stability than M02. Archiving is a loser a...

Tree Control with + and -
Hi, I was able to add root and items to my tree control, but it doesn't display the + and - (collapsed and expanded icon respectively). How can i display them ? Moreover, how can i diplay vertical lines binding the same level of items to eachother ? like in Windows Explorer... thx, Maileen "Maileen" <nospan@email.com> wrote in message news:eKi$xJjJEHA.1392@TK2MSFTNGP09.phx.gbl... > Hi, > > I was able to add root and items to my tree control, but it doesn't > display the + and - (collapsed and expanded icon respectively). > > How can i display...

Outlook Express Mail vs. Windows Mail (Vista)
I'm retiring my old computer which used Outlook Express as its email program. The computer that I will now be using runs Vista with Windows Mail. I have quite a few emails in various folders on my Outlook that I need to save for future reference. Is there a way to migrate those emails to Windows Mail? Please advise -- thanks! Import messages into Windows Mail from Outlook Express http://windows.microsoft.com/en-US/windows-vista/Import-messages-into-Windows-Mail-from-Outlook-Express -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "Ken...

#Temp vs @Temp memory vs disk etc.
Hi all I have a query where I materialise (materialize) a set of records to a temporary table. There are a number of reasons that I do this rather than use a CTE or derived table that for sake of discussion (for now at least) i'd like to assume are valid :-) For another reason I need to use dynamic sql because the nature of the UI is so fluid (many column combinations). I use a #temp table so that the result set is avaiable both inside and outside the dynamic calls. This all works fine I am considering @Temp because I hear that the table is entirely loaded into memo...

IE7 vs Firefox
I am trying to figure out why Firefox displays a big blue rectangle at www.factorwords.com whereas IE and Safari don't. TIA What version of each browser are you viewing it with? I tried looking at it with IE8, and I saw the blue rectangle as well. When I did a view source, the HTML for that area was: <table border=".75px" cellpadding="3" cellspacing="0" bordercolor="#0080FF" bgcolor="#CCE6FF" width="100%"> If you look at this HTML, you will notice that the table tag has the following attribute: bgc...

P6 Web vs. Project Server
Ok here is a twist. I have used MS Project and P6. When it comes to building Project Plans I prefer Project. At my old company we used P6 for the Project managers. When the Project Managers wanted to update their project us project planners would create a reflection project. The PM would go make their changes....we would review them and then merge them into the parent project on P6. Does Project Server 2007 offer a similar option? Goobie -- In the future, please post your Project Server questions in the microsoft.public.project.server newsgroup, as this newsgroup is dedic...

How do I graph a cell vs one that it changes for a range of valu.
One cell changes another cell as determined by a formula not explicitly contained in either cell. I want to range a cell from 0.5-1 in small increments and line-plot it vs the other. How do I express a range of values and the steps of increments? Hi Kentlm, > One cell changes another cell as determined by a formula not explicitly > contained in either cell. > I want to range a cell from 0.5-1 in small increments and line-plot it vs > the other. > How do I express a range of values and the steps of increments? It sounds like you want a Data Table. Look in Excel's Help ...

98Se vs. XP
Just bought money 2004 "designed for XP". Will it run on 98SE? What's the box say? <anonymous@discussions.microsoft.com> wrote in message news:cc9801c3eea5$e82ddc40$a001280a@phx.gbl... > Just bought money 2004 "designed for XP". Will it run on > 98SE? ...

Outlook vs. webaccess crm 4.0
Hi 1) Could someone specify the pros and cons (especially the difference in the "functionality" options) for the end users - if they use the Outlook client or if they use a Webbrowser? 2) What are most common ? thanks for any feedback... It's true you can do everything on the web version or the Outlook version. The biggest feature of CRM is the fact you can everything inside of Outlook and not have to go a different application. Outlook: 1 - Easier concept for end users (especially Sales folk) to grasp. "you don't need to learn a new application - it's ju...

Auto Account Number Generation
Here's a newbie question for which I have not yet been able to find a solution. Whenever creating a new account, I'd like the form to automatically display an account number in the accountnumber field that is one more than the max in the table. How can I automtically create this? That is how can I run a query on form load that looks up the current max account number then add one to it? ANy help would be appreciated. Only way to do this is through writing some code. For example you could achieve this using a callout. When you save a new account you can have the callout scan ...

SUMIF vs COUNTIF
I have a column populated with dates. I want a cell in another worksheet to count how many of the dates in the aforementioned column are less than a user defined date. I.e. I want the cell to display how many dates fall before 15th August. I am unsure as to how to write this correctly. Currently I have: =COUNTIF('Sheet1'!AH16:AH97, "<15/08/2005") Is this correct? What would SUMIF do in contrast? =COUNTIF('Sheet1'!AH16:AH97, "<"&Date(2005,08,15)) This just counts the instances. SUMIF can add up associated values in another column, such as AI...

MSN8 vs IE Download
FWIW, Last month I had successfully downloaded my AE credit card transactions using MSN8 and M3. This month got an error message, to the effect, M3 could not find the ofx file. Purchased M4 and tried to download again using MSN8; got the same error message. Tried IE with M4 and viola; success! Things that make you go hummmmmmmmmmmm............... ...

VS 7.1 IDE bug w/ Events
Hi, Might as well post here; I just came up with a few compiler errors; after changing several functions around. Here is what I have done: I have a dialog, with an existing OnNMRclickAvatarsLeft(NMHDR *pNMHDR, LRESULT *pResult) [NMRC] in it, I tab out this entire function for archival. I also remove its Message Map entry, I do not remove its function defenition. I attempt to add the same [NMRC] function again via right click and add event, it denies this saying the function already exists. I remove the function header, and add the function again via right click and add event. The IDE...

Appetime Women's Yukata Pips Collection Cherry Tree Watch #SVJ320031
Price:$100.00 Image: http://bestdeallocator.info/image.php?id=B0018BP294 Best deal: http://bestdeallocator.info/index.php?id=B0018BP294 Time and date indication Quartz 3 year battery life Water resistant 3BAR Plastic case and back plate Stainless steel bezel Mineral crystal glass Urethane strap Luminescence Case diameter: 42 millimeters Case Thickness: 10 millimeters Band Width: 19 millimeters If your watch has a soft plastic band such as a urethane band; do not leave the watch under a fluorescent lamp or direct sunlight for a long period o...

vba vs VB dotnet
I have a new project to use MS access as backend. I would like to know what adre the difference betwwen VBA and VB dotnet as front end? what is the best choise and what I need considre to use front end bwteen 2 choices? Your information is great appreciated, Souris wrote: > I have a new project to use MS access as backend. > > I would like to know what adre the difference betwwen VBA and VB > dotnet as front end? > > > what is the best choise and what I need considre to use front end > bwteen 2 choices? Well a big difference is that you can actually create a fr...

ByVal copy a variable
Hi, (vb.net vs2008) I understand the significance between memory pointers with a function using byVal and byRef. However I have code that I want to do something like this: Dim UsMailmsg As MailMessage = EmailOrderClass.createEmailOrder(False, cartOrderID) For nI As Integer = 0 To SendToEmailAddresses.Count - 1 EmailOrderClass.sendEmailOrder(CustomerAddress, ToEmailAddress, UsMailmsg) <------- this line Now When I am using the UsMailmsg, even though the function is specified as "byVal" it will always pass in as a reference to a mem...

PO Generator To Include On Hand Stock When Ordering to a Mstr Site
When using PO Generator we need to reorder to a Master Site but to have the suggested quantities for a particular item include quantities on hand rather than only quantities to satisfy any Order Up To Levels. In effect each Site calculation is based on Independent Site order values and only shortfalls are added to the quantities required at the Master Site. This does not reflect the true Net Demand for the item. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree&qu...

Cview and Tree control
I have an MDI application which renders opengl scenes in a document. The CView class continously calls opengl library and paints the scene. Here is a screenshot: http://limefocus.net/screenshot.jpg I would like to add a tree control inside the document to manupilate the image generated in the CView. Is it possible to embed a tree control in a CDocument? Thanks. Jess You are mixing the paradigms here. A document does not care how its data is represented. Question you shoud ask is if you can put a tree control in your view. The answer is : absolutely. You can use a splitter to put a t...

Money vs Financial Institution
My financial institution has direct statement, but requires 6 or more digit password, and money reqires a 4 digit pin. How do I fix this so that when I start money my bank statement download automatic. I have other accts setup, but money does not put a limit on their password. I upgraded from Money 2001, so far I have not seen the benefits of the upgrade. thks Skeeter The Money Online statement PIN/Password for a given bank is frequently different than the ATM PIN/ web site password for the exact same bank. Money is likely just quoting/enforcing the restrictions that the bank has told ...

Help me to generate a report
I need some help on producing this report - The data: Users Clients Run ID Solutions Update Solutions Brenda Walmart 1234 aaaa System Generated Brenda Walmart 1234 bbbb System Generated Brenda Walmart 1234 cccc Reject Brenda Walmart 4567 aaaa Accept Brenda Walmart 4567 eeee Deferred Brenda Target 7890 ffff System Generated Brenda Target 7890 gggg System Generated John ShopKo 8901 cccc System Generated John ShopKo 8901 ffff System Generated John ShopKo 9012 dddd System Generated Eric Giant 1012 aaaa Reject Eric Giant 1023 mmmm Accept Eric Subway 1458 nnnn System Generated Eric Cisco 6548 eeee...

Mail-enabled contacts vs Administrative groups
Hi, Since my Exchange 2003 was switched to native mode I'm not able to select a administrative group where I want to create it. Is that normal? "Jocelyn" <thefreefly@gmail.com> wrote: >Since my Exchange 2003 was switched to native mode I'm not able to >select a administrative group where I want to create it. Is that >normal? Since those are just AD objects I'm not sure I understand why you care. When Exchange had its own directory the "site" owned a directory object. But Exchange doesn't have its own directory anymore. -- Rich Matheise...

XP vs Vista vs 7
Isn't it true that Windows XP actually did everything Windows Vista and Windows 7 does with less RAM, less memory, less user frustration, less expense, no compatibility issues and maybe less compromise of privacy. Why are we not given a choice of which to spend our money on? Is XP gone or coming back like the turntable? No, it is not true "Ernesto Torvals" <Ernesto Torvals@discussions.microsoft.com> wrote in message news:87B4BD53-B796-4785-AB26-7808B0998B77@microsoft.com... > Isn't it true that Windows XP actually did everything Windows Vista and &g...

Personal vs Business??
What to do? If I'm an employee tracking my personal finances I can easily see using the basic Money programs. If I'm running a small business I can see using Money for small business. The question is....[since I don't yet own the small business version]...will I also be able to manage my personal finances along with my business finances with the small business version of Money or do I have to use both, somehow??? Hello Pat, Based upon the possibility of using Money for a business application, I would purchase the Small Business Version. If you search the WWW, you can p...

XLReportGen 2.5
XLReportGen is a report generator for Microsoft Excel that outputs reports in Microsoft Excel spreadsheet format. If you know how to use Microsoft Excel and write SQL statements, you can use XLReportGen to create all kinds of reports as you need. Benefit: * Use Microsoft Excel as your reporting tool. * Easy to use. Just Microsoft Excel and SQL. * Powerful and flexible. Microsoft Excel are powerful and flexible. * Saves money. Do not need to buy extra costly reporting tools. * Saves time. Reduce development time and training time. * Improves productivity. Reports are in familiar formats. * For...

Coalesce vs isnull
I have the following select statement with about 10 COALESCE statements. Is this the best way to do this or does it really matter? I had seen in some articles that COALESCE was not as efficient as ISNULL but I assume that would be negligible. SELECT .... WHERE @Type % O.CType = 0 and dbo.fn_Related_viaBina(@EnvironmentID, @ID) = 1 AND ( (V.Description like COALESCE(@SearchFix, V.Description)) OR (@SearchFix IS NULL) OR (vw_ConditionList.Description like COALESCE(@SearchFix, vw_ConditionList.Description)) ) and ( B.BinID = COALESCE(@BinId, B.BinID) OR ...