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
1054 Views

Similar Articles

[PageSpeed] 56

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:

Domain Controller vs. Workgroup
I will setting up a single server 2003 Standard edition(dual cpu) 4GB ram. This is the only server accounting will have. There is no domain controller. GP will be installed on this server and SQL 2005 express will be installed here. It may also be used as a Terminal Server. There will be 4 users. THe functionality used will be GL,AP,AR,Payroll (25 employees) Bank Rec and Report writer. Which is better, configuring the server as Domain Server (GP will be the only application on this server) or workgroup. Either way I would still like to configure it as a Terminal Server. Thanks You ...

how to generate random number
I want to generate random numbers within the range of 0 to 10. rand () function doesnot take any arguments.I don't know how to do it.Thanks in advance Jeevan Hallo Fenn! > I want to generate random numbers within the range of 0 to 10. rand () > function doesnot take any arguments.I don't know how to do it.Thanks in > advance You just can use %11 (modulo 11). This generates a random number between 0 and 10 (inklusive). But using modulo they are not evenly distributed. The number 9 and 10 are choosen 1 times less on 2978 trials. If you want to have an even distributed r...

General Question: Attribute vs. Element
Hi All, This is a pretty simple question, but with possibly a complex answer. I was wondering if anybody had any opinions or links for "rules" as to when to use elements and when to use attributes within XML. For a quick example, think of a file system represented by XML. Method 1: Attributes <FileSystem> <Folder name="MyFolder"> <File name="test1.txt" size="3752" /> <File name="test2.txt" size="1729" /> </Folder> <Folder name="AnotherFolder"> <File name=&...

VS 2010 & Master Pages
Does anyone know if there is an option to tell VS 2010 NOT to use Master Pages as the default page/content type in ASP.NET Web Application Projects? I find it hard to believe that Microsoft just expects everyone to just use Master Pages by default now. -Scott "Scott M." <s-mar@nospam.nospam> wrote in news:#2pMVMMgKHA.1112@TK2MSFTNGP04.phx.gbl: > Does anyone know if there is an option to tell VS 2010 NOT to use > Master Pages as the default page/content type in ASP.NET Web > Application Projects? There is not. The project template contains a ...

Newbie, Find depth of binary tree
Hi Sorry for this stupid question, being a newbie I'm no very familiar with pointers I need a fuction to find the depth of a binary tree, can anyone help me? or point in the right direction. :-) thanks in advanced "verci" <vercireyes@morexpress.net> wrote in message news:e5Z2WV2aDHA.388@TK2MSFTNGP10.phx.gbl... > > Sorry for this stupid question, being a newbie I'm no very familiar with > pointers I need a fuction to find the depth of a binary tree, can anyone > help me? or point in the right direction. :-) I assume you want the maximum depth of the bin...

VS2005 and VS 6.0
Is there a definitive reference for how to adapt the different features in 2005 for 6.0? e.g., I can't seem to figure out how to override functions like OnPaint, etc. I see them in the class view, but when clicked they lead me to the afxwin.h file's declarations. Here's where the class wizard came in handy, I know that there's no more class wizard in .net but how to use that functionality without? I need a friggin tutorial for this... just got VS2005 and want to start re-doing my 6.0 project. For now all I want is to override member functions for the MFC classes... a...

VS 2008 stop working when interface changes
I have a WPF project with several interfaces which are used in UserControls I attempt to change an event on one of the interfaces and VS 2008 shuts down with a COMPILER ERROR WTF!!! At the present I have tried just about everything I know to get around this. Any ideas? It is VS 2008 Pro. Thanks LS "Lloyd Sheen" <a@b.c> wrote in message news:u0zB170dKHA.5608@TK2MSFTNGP05.phx.gbl... > I have a WPF project with several interfaces which are used in > UserControls > > I attempt to change an event on one of the interfaces and VS 2008 shu...

Block diagram - Multi-tree Square shape issue
Now, this is really getting my boxers in a snit - the Multi-tree Square shape ONLY allows 6 nodes (yes, I said SIX) to be added! I can't even cheat by hanging another shape below it because Visio is SO SMART it won't let me overlap lines in a shape. (Gee, I wish I had the brains to think for myself, but hey, MS knows better) Now, before I get a bunch of trolls that do nothing to help but call people MS bashers and trolls, I have been working with MS products since LanMan ver. 1.0 (How many of you can say that!) - I like most MS products VERY much - it's just stupid shi+ l...

Classes Vs XmlDataDocument
Hi, I have a set of nested object classes that now i have to serialize/deserialize to make webservice calls. I was thinking wouldn't it be better to use an XML Data document instead of using classes so i can import/export xml with ease and also i can update my schema without compiling the code. What advantages/disadvantages do you guys see in taking this approach. Any kind of suggestions are welcome. Thanks! Vish wrote: > I have a set of nested object classes that now i have to > serialize/deserialize to make webservice calls. I was thinking wouldn't it > be bett...

speed vs. modularity
I have a question about calling functions. If you are trying to make your program as fast as possible, would it be better to have say a couple big functions and not break up the possible functions you could make, or does it matter as far as time goes? What is faster, a big main, or a small main with a lot of function calls? -- ______________________ ~Beau On Mon, 25 Oct 2004 19:39:30 -0500, "Cephus�" <beau@highway.net> wrote: >I have a question about calling functions. If you are trying to make your >program as fast as possible, would it be better to have say...

Crystal Reports Runtime 8.5 vs. 9.2
Our application installs and uses CR 9.2 files. Afterwards a 3rd party app relying 8.5 CR no longer works. Reinstall that app and then ours doesn't work. Reinstall ours and then that app doesn't work. And so on... Are one of these applications installing\using CR improperly or is it impossible to run 8.5 and 9.2 side-by-side? Shouldn't app coded against 8.5 work if the runtime is upped to 9.2? ...

javascript generated html
Suppose I download a html file with javascript in it, for example, <html> <body> <script language="JavaScript"> document.write("Hello"); </script> </body> </html> How can I translate that to pure html, <html> <body> Hello </body> </html> I am looking for a c++ solution. Thanks, qk quikquic@yahoo.com (quikquic@yahoo.com) writes: > Suppose I download a html file with javascript in it, for example, .... > <script language="JavaScript"> > document.write("Hello...

generating part numbers
I wrote a simple spreadsheet that we enter all of our product we purchase in, and it calculates the reselling price very nicely. Over time this has grown to have a few thousand part numbers. Now we are going to produce our own catalog, and I would like to change the supplier part number, into a unique number to publish in our catalog. Doing this individually would take forever, so I was hoping to make a simple formula to automate it. By multiplying the supplier part number by 1.05 for example would work, but the problem is that many of the manufacturers part numbers have a letter in it. F...

Slow Receipt & Journal Generation
After closing a sale our computer takes 30 - 90 seconds to print the receipt. The journal viewer is also very slow. However when I edit the receipts in the Manager, the printer prints almost immediately. It only slows down for actual transactions in the POS program. I am using OPOS instead of the windows driver and the healthcheck doesn't show any problem with the printer or the cash drawer. The printer is hooked up to COM1 through the cash drawer. The baud rate is set to 9600 and doesn't seem to work when I set it to 19200, or 38400. I have also tried reinstalling the d...

Outlook vs Outlook Express #13
I've been using MS Office Outlook 2003. I also have a short cut for Outlook Express. What is the difference in these two apps? TIA Outlook is a Personal Information Manager (mail, calendar, tasks, etc) where OE is a mail & news program. "dp" <dp@discussions.microsoft.com> wrote in message news:E2C274B0-623A-4449-AFDC-715802C700A1@microsoft.com... > I've been using MS Office Outlook 2003. I also have a short cut for > Outlook > Express. What is the difference in these two apps? ...

Transfer Category vs Transfer Transaction Type?
I have several accounts which I transfer money between using online banking. Money allows two ways to record this: Either create a Transaction with a type of Transfer, or create a withdrawal Transaction and set its Category to 'Transfer To: Accountname' Im wondering what impact it has if I choose one way over the other. Would it affect any reports, or is there anything I should be aware of when choosing? At the moment Im not even consistent in which one I pick, and so Im worried I could be messing up my accounts. Also, If I wanted to record a balance payment to my credit card, shoul...

when use tree control why no buttons are shown
Hi all, I created a tree control, and set the style of having buttons. But when it is shown why it has no buttons. The codes are like: (1) create tree m_pTree=new CTreeDlgCtrl(); m_pTree->Create(WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES | TVS_DISABLEDRAGDROP,CRect(x,y,w,h),this->GetParent()->GetParent(),IDC_TREE1); (2) add item to tree TVINSERTSTRUCT tvInsert; tvInsert.hParent = NULL; tvInsert.hInsertAfter = NULL; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("Unite...

Bush vs Sadam
<b> <a href="http://iraq.in41.ws/wariniraq.html">War in Iraq</a>! </b> What was the main reason for Bush in <a href="http://iraq.in41.ws/iraqwar.html">Iraq war</a>? Fantom forces are going to redraw the <a href="http://iraq.in41.ws/mapofiraq.html">Map of Iraq</a>! <i><a href="http://iraq.in41.ws/iraqnews.html">iraq news</a> from In41.</i> -- wariniraq ------------------------------------------------------------------------ wariniraq's Profile: http://www.excelforum.com/memb...

CreatePointFont creates font of different size in VS 2005 vs. VS 2
Hi, I 'm converting projects from VS 2003 to VS 2005. One suprising thing is a different visible font size on the screen (at some places in my apps) It seem that : font.CreatePointFont(80, "Arial"); now creates a slightly larger font (on a 96 dpi Monitor) then before (lfHeight=-11 vs. -10). Is this indented? BR, Uwe ...

Receipt Date vs GL Posting Date
Hello, I created a Shipment/Invoice Receiving transaction and accepted the default receipt date (which is the current date) as 4/3/2010. I saved the transaction into a batch and print the batch edit list for verification. I then found out that the date is wrong and changed the date to 22/2/2010. I printed the edit list again and confirmed that the date has been changed. I then proceed to posting the batch. After posting, I found out that the GL Posting Date was maintained as 4/3/2010 and was not changed to 22/2/2010. This has cause error in the accounting and I had to make the re...

Random Variable Generator
I have been wondering if this is possible in Excel. Example: Say you want to put together a tournament. You have 30 names ( variable that is dynamic) and you want to seperate into random teams o 2 (another variable that can be dynamic). Would that be possible to d in excel, generate random groupings within a list? Thank rowed ----------------------------------------------------------------------- Posted via http://www.mcse.m ----------------------------------------------------------------------- View this thread: http://www.mcse.ms/message386425.htm List the 30 names in a column. In...

Excel 2007: Percentile vs Percent when It comes to Color Scaling?
Hi, When it comes to conditional formatting and filled column coloring, should "Percentile" or "Percent" be used, and why? Thanks ...

Generating Unicode characters in a cell using formulas
With older multibyte Chinese code sets like Big5, I could create a large list or table of Chinese characherts by generating their two components with a formula like =CHAR(HEX2DEC(LEFT(A5,2)))&CHAR(HEX2DEC(RIGHT(A5,2))) were the hex code for the character (eg. A440) was in tyhe target cell A5. With Unicode, all I get are the two individual characters that (in Big5 anyway) made up the multi-byte code for a character. BTW: In the case above, Big5 A440 is Unicode U+4e00, the character for "one" 一. Hi Geoff, You will have to create a User Defined Function for use on your w...

Generate a unique number of list
Hey all, I have a list of number which some is repeated, how can I regenerate a list with unique number. e.g 1 2 1 5 3 5 Expected Result 1 2 5 3 Thanks for any one who can help. -- Terence Chan ------------------------------------------------------------------------ Terence Chan's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=26963 View this thread: http://www.excelforum.com/showthread.php?threadid=467164 Hi Terence One way Mark your range of data, Data>Filter>Advanced Filter and Select Unique values only. Copy the data to a new location. Rega...

generating a unique number in specific format
Hi, I currently have a stored procedure that generates a unique reference number. I did not use the SQL built in identity field to auto number because the number needed to be in a custom format. The format is CC (application identifier), a two digit year, a two digit month and a three digit unique number. For example CC0909001, for September 2009. The procedure runs a MAX query on the three digit unique number and adds 1 before generating the custom refernce and adding it to a primary key field. The procedure has worked fine but is now being used for multi user access a...