|
thanks for your answer & time. few things got clear after reading your answer but still few area is not clear and those are.
1) Any code that should be loaded (like a method) will eventually use memory. I say eventually because it may not have been jitted yet, but when it is, it will use memory. But that will happen only once. It is not important if you have 1 instance or 1000 instances. The method is only once on memory.
we know that JIT compiler generate machine code at run time. so when i will create a instance of employee class then how much memory will be allocated?
when we call method like instance.methodname() then memory will be allocated for method? but how much memory will allocated i just can not visualize.
u said - The method is only once on memory. how long method will be on memory ? until we dispose that instance ?
another thing u did not say like if local variable declare in method where they will be stored....in heap or stack?
2) u said :- Any reference (the "pointer") is 4 bytes on 32-computers and 8 bytes on 64-bit computers.
can u plzz explain in more detail the point 2 with sample code. which references u r talking about here.
a class may have many data member like string,double,float & datetime etc.
3) u said :- Also, virtual methods (and interfaces are included) occupy memory for their vtable... again, it is once for the class, it is not important if you have 1 instance or 1 million.
i just like to know how memory is occupied for interface ? because interface is abstract not concrete. can u please come with sample code just to show me when & how memory is allocated for interface
4) u said :- value types and the reference themselves are kept on the "actual" location (stack or heap) while the created reference type object is always on the heap, at another location.
the above point 4 not at all clear. we know when we create instance then memory is allocated for that instance is on heap not stack. please discuss the point 4 in more details with example.
i apologize that many area still not clear and here i discuss with point wise. so when u give answer then please give it point wise and also with example for better visualization.
if possible give me some links of site from where class, instance and memory allocation doubts can be more clear. thanks
tbhattacharjee
|
|
|
|
|
1. The method must be loaded into memory (jitted) once for a method to run. So, if the method is already in memory, doing instance.methodname() does not allocates any memory (if the method allocates memory when executing it is another story).
But, how much memory for the jit? Well, that depends on the size of the method... I don't know exactly, but it is sure that a return x; will be pretty small.
The method is usually on memory forever once you execute it. You can dispose all the objects, you may force garbage collections, but loaded assemblies remain in memory. (there are collective assemblies, but that's far away from normal usage).
2.
string x = "Test";
string y = x;
"Test" is only once in memory. Both x and y are the references to "Test".
x and y will each one occupy 4 bytes of the stack (if they are declared in the body of a method) or will add 4 bytes to the size of the class/struct where they are declared, if the computer is 32 bits. If the computer is 64bits, then the size of x and y will be 8 (a 64-bit address).
3. When you receive an object of type ISomeInterface... it is surely of a concrete type, right? But, how the someInterface.Call() finds the ConcreteClass.Call()?
There is such VirtualTable for the interface, which in fact has the address (again, 4 or 8 bytes) of the real method.
In fact, I don't know how many size implementing an interface (note that: implementing... 3 classes that implement ISomeInterface means there is 3 times the size of such interface-implementation required), but each method that exist in the interface will probably add 4 or 8 bytes for their address, but it is possible that .Net does some optimizations to reduce this (I really don't know).
4. I already answered it on the answer to the other question. If you do new SomeType() and such type has an int field, such int field will be in the heap memory of SomeType.
|
|
|
|
|
Hi,
I am building up reliable multicast file transfer tool. Please let me know any library available in c# for forward error correction algorithm.
Regards,
Raghu Sunkara.
s
|
|
|
|
|
|
Have you looked at ZeroMQ and using epgm binding?
If at first you don't succeed, look for directions in the trash.
|
|
|
|
|
Hi,
Thanks for reply. i havent played with ZeroMQ. As a beginer i would like to know, will ZeroMq solves reliable multicast file transfer problem? Please let me know waiting for your reply.
Regards,
Raghu Sunkara.
s
|
|
|
|
|
Need to get the code to implement remote desktop using VNC protocol in dot net
|
|
|
|
|
Try the VNC web site for details.
Use the best guess
|
|
|
|
|
See here[^].
That's a library that implements VNC, and you can use it in .NET; you'd still have to write a client to use it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You could use DotNetVNC/[^].
A similar question has been posted in here before[^]. You might want to use the search function before next time.
Or you use VNC#[^], as Eddy mentioned before.
|
|
|
|
|
Hello
here is a little difficulty:-
there is a program:- (source:pg 750: C# 4 Complete Reference by Herbert Schildt , McGrawHill )
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
namespace scratchpad3
{
class Program
{
public static void Main()
{
int[] a = { 1, 2, 3, 4, 5 };
MyThread mt1 = new MyThread("Child #1", a);
MyThread mt2 = new MyThread("Child #2", a);
mt1.Thrd.Join();
mt2.Thrd.Join();
}
}
class SumArray
{
int sum;
object lockOn = new object();
public int SumIt(int[] nums)
{
lock (lockOn)
{
sum = 0;
for (int i = 0; i < nums.Length; i++)
{
sum += nums[i];
Console.WriteLine("Running total for " + Thread.CurrentThread.Name + " is " + sum);
Console.Read();
Thread.Sleep(10);
}
return sum;
}
}
}
class MyThread {
public Thread Thrd;
int[] a;
int answer;
static SumArray sa = new SumArray();
public MyThread(string name, int[] nums)
{
a = nums;
Thrd = new Thread(this.Run);
Thrd.Name = name;
Thrd.Start();
}
void Run()
{
Console.WriteLine(Thrd.Name + " starting.");
answer = sa.SumIt(a);
Console.WriteLine("Sum for " + Thrd.Name + " is " + answer);
Console.WriteLine(Thrd.Name + " terminating.");
Console.Read();
}
}
}
the o/p is given as;-
Child #1 starting.
Running total for Child #1 is 1
Child #2 starting.
Running total for Child #1 is 3
Running total for Child #1 is 6
Running total for Child #1 is 10
Running total for Child #1 is 15
Running total for Child #2 is 1
Sum for Child #1 is 15
Child #1 terminating.
Running total for Child #2 is 3
Running total for Child #2 is 6
Running total for Child #2 is 10
Running total for Child #2 is 15
Sum for Child #2 is 15
Child #2 terminating.
My difficulty is at line that is starred
that line shows a delegate but you see in the form: Thrd = new Thread(this.Run);
shouldn't this be: Thrd = new Thread(this.Run()); ---- Is this a paradigm shift or ----????????????????????
|
|
|
|
|
As is explained here[^], the argument to the Thread class is A ThreadStart delegate that represents the methods to be invoked when this thread begins executing.
So long as you are pointing to a method that exists and is visible to this class, you don't need to worry about () .
|
|
|
|
|
Hello Abhinab
If you may put it in length slightly, it will help me
---------------
Yea another aspect
How to award points for a good answer
|
|
|
|
|
You're not calling the function at that point, so no parentheses.
|
|
|
|
|
Calling a method is one thing. Getting the method "pointer" is another thing.
When you create a thread, you want the Thread to execute a method. You should not execute the method yourself. So, you give a method name, not a call, to the thread.
|
|
|
|
|
I want to use this code
TextBox1.DataBindings.Add("Text",DataTable,"FName");
in web application project but it does,t have the library.in web form the library is in the system.windows.forms.controlbindingscoll… but I can,t handle it in web application.what is the solution?
|
|
|
|
|
Ask your question here[^].
|
|
|
|
|
behrad kiani wrote: I want to use this code You can, if you write Windows-applications.
behrad kiani wrote: but I can,t handle it in web application. Try the knowledgebase[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
my project name:webcam based credit card reader with face recognition
i search on library in c# to read bar code by using cam but i don't found
so if anybody can help me i need this library coz i don't have time plz help me?? confused:
|
|
|
|
|
What the heck does "library in c# to read bar code by using cam" have to do with "webcam based credit card reader with face recognition"?
I have never seen a credit card with a barcode on it, and strangely, I've never seen a face with a (readable) barcode on it.
Perhaps if you started by searching for relevant information it might speed your project along...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
|
|
|
i have a table which has attributes such as fname,lname and address.i can show the details of all these attributes togheter with tablegridview and other data objects but I cant access to specific attribute.for example I want to show just the fname in the texbox1.what is the command
|
|
|
|
|
Assuming the UI is WPF/Silverlight (View) in the subject.
Bind the view to a datacontext, this datacontext should have the collection, bind the grid to the collection, bind the column to the fieldin the collection.
Never underestimate the power of human stupidity
RAH
|
|
|
|