Click here to Skip to main content
15,885,868 members
Home / Discussions / C#
   

C#

 
GeneralRe: Few question about static class c# Pin
Tridip Bhattacharjee25-Mar-13 21:31
professionalTridip Bhattacharjee25-Mar-13 21:31 
GeneralRe: Few question about static class c# Pin
Marco Bertschi25-Mar-13 22:20
protectorMarco Bertschi25-Mar-13 22:20 
AnswerRe: Few question about static class c# Pin
DaveyM6925-Mar-13 9:45
professionalDaveyM6925-Mar-13 9:45 
AnswerRe: Few question about static class c# Pin
V.25-Mar-13 23:04
professionalV.25-Mar-13 23:04 
Questionhow memory is allocated for class, class data member and member function & interface and class instance ? Pin
Tridip Bhattacharjee25-Mar-13 4:59
professionalTridip Bhattacharjee25-Mar-13 4:59 
AnswerRe: how memory is allocated for class, class data member and member function & interface and class instance ? Pin
Paulo Zemek25-Mar-13 5:28
mvaPaulo Zemek25-Mar-13 5:28 
GeneralRe: how memory is allocated for class, class data member and member function & interface and class instance ? Pin
Tridip Bhattacharjee25-Mar-13 9:26
professionalTridip Bhattacharjee25-Mar-13 9:26 
GeneralRe: how memory is allocated for class, class data member and member function & interface and class instance ? Pin
Paulo Zemek25-Mar-13 9:46
mvaPaulo Zemek25-Mar-13 9:46 
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.
C#
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.
QuestionAny C# library for Forward error correction. Pin
iamraghusunkara25-Mar-13 4:33
iamraghusunkara25-Mar-13 4:33 
AnswerRe: Any C# library for Forward error correction. Pin
Marco Bertschi25-Mar-13 6:17
protectorMarco Bertschi25-Mar-13 6:17 
AnswerRe: Any C# library for Forward error correction. Pin
unclepaul25-Mar-13 10:44
unclepaul25-Mar-13 10:44 
GeneralRe: Any C# library for Forward error correction. Pin
iamraghusunkara25-Mar-13 19:55
iamraghusunkara25-Mar-13 19:55 
QuestionRemote desktop using VNC Pin
superselector25-Mar-13 1:27
superselector25-Mar-13 1:27 
AnswerRe: Remote desktop using VNC Pin
Richard MacCutchan25-Mar-13 1:35
mveRichard MacCutchan25-Mar-13 1:35 
AnswerRe: Remote desktop using VNC Pin
Eddy Vluggen25-Mar-13 2:03
professionalEddy Vluggen25-Mar-13 2:03 
AnswerRe: Remote desktop using VNC Pin
Marco Bertschi25-Mar-13 6:22
protectorMarco Bertschi25-Mar-13 6:22 
Questiondelegate difficulty Pin
Member 993942324-Mar-13 21:45
Member 993942324-Mar-13 21:45 
AnswerRe: delegate difficulty Pin
Abhinav S24-Mar-13 22:29
Abhinav S24-Mar-13 22:29 
GeneralRe: delegate difficulty Pin
Member 993942325-Mar-13 3:42
Member 993942325-Mar-13 3:42 
GeneralRe: delegate difficulty Pin
PIEBALDconsult25-Mar-13 5:01
mvePIEBALDconsult25-Mar-13 5:01 
AnswerRe: delegate difficulty Pin
Paulo Zemek25-Mar-13 5:34
mvaPaulo Zemek25-Mar-13 5:34 
QuestionHow to use databindings class in web application? Pin
behrad kiani24-Mar-13 6:56
behrad kiani24-Mar-13 6:56 
AnswerRe: How to use databindings class in web application? Pin
Dave Kreskowiak24-Mar-13 7:33
mveDave Kreskowiak24-Mar-13 7:33 
AnswerRe: How to use databindings class in web application? Pin
Eddy Vluggen24-Mar-13 23:33
professionalEddy Vluggen24-Mar-13 23:33 
Questionwebcam based credit card reader with face recognition Pin
nabil j24-Mar-13 5:44
nabil j24-Mar-13 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.