We have a main method which calls a sub method 50 times and in turn the sub method calls one more method 5 times. From the first the datatable is passed by byval and one or two value types are passed by byval. The method doesn't make any changes to the variables
1. Byval or Byref - which will be faster-multiple times and multilevels calling?
2. Will that be a good idea to have multiple levels of methods to be called multiple times. We have lot of local variables. Will the garbage collectors's headache be more in creating and destroying the objects?
ByVal means that the method will create its own copy of the variable, and any changes will not be passed back to the method that called it.
ByRef means the method will use the variable you passed in and update it.
Some objects (I believe DataTables are one example of this) are always passed ByRef even if you specify ByVal because they are so complex.
It sounds like what you want to do is use ByRef. Running a method that updates a couple variables 50 * 5 = 250 times shouldn't be too much for an average computer today. If you were updating several hundreds of thousands than you may worry about it more.
First: abandon any notion of ByRef vs. ByVal from VB6.
Second: there is a difference with ByVal and ByRef wrt object instances.
What ByRef and ByVal indicate are which memory address to copy to the method's stack.
Lets look at the following code:
Private Sub DataTableCreator()<br />
Dim dt As New DataTable()<br />
End Sub<br />
Private Sub ByValReceiver(ByVal valdt As DataTable)<br />
valdt = Nothing<br />
End Sub<br />
Private Sub ByRefReceiver(ByRef refdt As DataTable)<br />
refdt = Nothing<br />
End Sub<br />
ByValReceiver will take in the memory address of the object on the heap and assign it to a local variable "valdt" on it's stack.
ByRefReceiver will take in the memory address of the variable "dt" from DataTableCreator's stack and assign that to refdt.
So what does this do for you? Two things.
1) If you run the code you'll see ByValReceiver won't effect dt in DataTableCreator, but ByRefReceiver does.
When you assign Nothing you're in effect clearing the memory reference from the variable.
refdt is really a reference to a reference (or pointer to a pointer in in the old days **p), setting it to nothing clears the real reference to the DataTable, which is dt in DataTableCreator.
2) I can't prove this since .Net can be a black box, but I fully expect that nesting calls with ByRef will cause multiple dereferencing steps (going to the memory address in the variable) to get back to the heap.
If you used refdt, first it must dereference to dt, then dereference dt to get to the actual DataTable instance on the heap.
This would actually marginally slow things down.
ByRef is required for when you want value types, which are held on the local stack (i.e. integer, long, structures etc) to be modified by the called method.
Think out parameters.
Objects should be handed down ByVal, unless you really want to use the trick above!
The method doesn't make any changes to the variables
Then you should not pass anything by reference.
Byval or Byref - which will be faster-multiple times and multilevels calling?
ByVal will be faster, and that is the default way of passing parameters.
When you pass an object by value, you are passing a copy of the reference to the object, and it will be handled just as afficiently as a local variable in the method.
When you pass an object by reference, you are passing a reference to the reference to the object. Whenever you use it in the method, it has to be dereferenced, which adds a small overhead each time.
The ByVal and ByRef keywords are mostly kept for compatibility reasons. In object oriented programming they are very rarely used at all.
Will that be a good idea to have multiple levels of methods to be called multiple times.
Unless you are making a huge number of calls to the methods, it doesn't matter much.
We have lot of local variables. Will the garbage collectors's headache be more in creating and destroying the objects?
Local variables are allocated on the stack, and don't have to be garbage collected at all. If you have local variables that are references, and create objects for those references, the objects will of course be garbage collected.
Creating and freeing objects are considerably cheaper in .NET than it was in VB6. As long as you make use of the objects, you should not normally be concerned with the cost of creating and freeing them. If you create and free the same kind of objects a lot, you might consider a way of reusing them, but on the other hand many objects are not even built to be reused in that way.
i m developing a ftp in vb.net,it is connecting to server and when
using ftpfindfirstfile it is returing some value.but the problem is with
Structure WIN32_FIND_DATA cfilename it is fixed string in vb but how convert
this in to vb.net,
if anyone provide wininet api it will be great help
i am using vb.net 2005, my problem is i am display a word file in webbrowser control by converting it in htm format but when i am press Ctrl+P key the printDialog appears..
how can i disable these keys ????
is there any option to block the user from printing the pages....????
please help....Thankx in advance for sweet cooperation
Be A Good S/W Eng... Life is swing with you..Enjoy..
Try setting the WebBrowserShortcutsEnabled to false. This stops my control from doing anything on Ctrl+P, however the program I checked it in had a keypress handler on the form itself.
Handle the webbrowser's KeyUp event:
If e.KeyCode = Keys.P Then<br />
If e.Control Then<br />
' do nothing with this.<br />
e.Handled = True<br />
End If<br />
It ought to be that setting e.Handled as true will stop the control from doing anything when Ctrl+P is pressed.
BTW it needs to be KeyUp because KeyPress has no easily accessible value (and is a pain).
Yet another spam post on yet another forum!
I am the lazy one, who sleeps as it suits him, codes what he wishes, and has many years to look forward to.
I love being a student.
i wan to do one crystal report by takin combination.
the report should look like this.
sl.No Caste of student no of students fees paid
caste n no of students v r takin from admission table.
amount paid from feereceipt table.
caste should be distinct n no of students should be respectable to that.
We used this query
SELECT a.CasteOFStu AS Category, (select count(*) from admission) AS NoOfStudents, (Select Sum(FeesReceiptDetails.amount) from FeesReceiptDetails,FeesReceipt where FeesReceipt.ReceiptNo=FeesReceiptDetails.REceiptNo) AS TotalAmount
FROM Admission AS a, FeesReceipt AS b
GROUP BY a.CasteOFStu;
but its givin total no means over all no of students irrespective of caste.
can u give me any fair idea of any query which has solution to above problem r any other crystal report functionality to help us in this condition.