Click here to Skip to main content
15,891,204 members
Home / Discussions / C#
   

C#

 
GeneralRe: File.Move/create just won't work! Pin
Goaty6510926-Mar-13 8:51
Goaty6510926-Mar-13 8:51 
GeneralRe: File.Move/create just won't work! Pin
Richard MacCutchan26-Mar-13 9:14
mveRichard MacCutchan26-Mar-13 9:14 
GeneralRe: File.Move/create just won't work! Pin
Goaty6510926-Mar-13 18:43
Goaty6510926-Mar-13 18:43 
GeneralRe: File.Move/create just won't work! Pin
Goaty6510926-Mar-13 19:42
Goaty6510926-Mar-13 19:42 
GeneralRe: File.Move/create just won't work! Pin
Richard MacCutchan26-Mar-13 22:42
mveRichard MacCutchan26-Mar-13 22:42 
QuestionI want to add progress bar for ftp download for the following code Pin
Friendsaa25-Mar-13 10:25
Friendsaa25-Mar-13 10:25 
AnswerRe: I want to add progress bar for ftp download for the following code Pin
Abhinav S25-Mar-13 16:50
Abhinav S25-Mar-13 16:50 
AnswerRe: I want to add progress bar for ftp download for the following code Pin
GuyThiebaut25-Mar-13 22:39
professionalGuyThiebaut25-Mar-13 22:39 
QuestionWhat is Jabber client ? Pin
Tridip Bhattacharjee25-Mar-13 9:49
professionalTridip Bhattacharjee25-Mar-13 9:49 
AnswerRe: What is Jabber client ? Pin
Peter_in_278025-Mar-13 10:54
professionalPeter_in_278025-Mar-13 10:54 
AnswerRe: What is Jabber client ? Pin
Dave Kreskowiak25-Mar-13 11:01
mveDave Kreskowiak25-Mar-13 11:01 
GeneralRe: What is Jabber client ? Pin
Tridip Bhattacharjee25-Mar-13 21:27
professionalTridip Bhattacharjee25-Mar-13 21:27 
GeneralRe: What is Jabber client ? Pin
Dave Kreskowiak26-Mar-13 1:44
mveDave Kreskowiak26-Mar-13 1:44 
AnswerRe: What is Jabber client ? Pin
Pete O'Hanlon25-Mar-13 22:40
mvePete O'Hanlon25-Mar-13 22:40 
AnswerRe: What is Jabber client ? Pin
Richard MacCutchan25-Mar-13 23:50
mveRichard MacCutchan25-Mar-13 23:50 
QuestionSerialization and object versioning Pin
Abyss25-Mar-13 9:39
Abyss25-Mar-13 9:39 
AnswerRe: Serialization and object versioning Pin
Eddy Vluggen25-Mar-13 23:31
professionalEddy Vluggen25-Mar-13 23:31 
QuestionHow to do code optimization in c# apps Pin
Tridip Bhattacharjee25-Mar-13 9:30
professionalTridip Bhattacharjee25-Mar-13 9:30 
GeneralRe: How to do code optimization in c# apps Pin
harold aptroot25-Mar-13 10:41
harold aptroot25-Mar-13 10:41 
AnswerRe: How to do code optimization in c# apps Pin
jschell26-Mar-13 8:39
jschell26-Mar-13 8:39 
QuestionFew question about static class c# Pin
Tridip Bhattacharjee25-Mar-13 5:01
professionalTridip Bhattacharjee25-Mar-13 5:01 
AnswerRe: Few question about static class c# Pin
PIEBALDconsult25-Mar-13 5:14
mvePIEBALDconsult25-Mar-13 5:14 
AnswerRe: Few question about static class c# Pin
Paulo Zemek25-Mar-13 5:39
mvaPaulo Zemek25-Mar-13 5:39 
GeneralRe: Few question about static class c# Pin
Tridip Bhattacharjee25-Mar-13 8:43
professionalTridip Bhattacharjee25-Mar-13 8:43 
GeneralRe: Few question about static class c# Pin
Paulo Zemek25-Mar-13 9:36
mvaPaulo Zemek25-Mar-13 9:36 
In any method...
C#
int i = 5; // the value 5 is on stack.
MyObject myObject = new MyObject();
// as discussed, the myObject reference is on stack, but the MyObject content is on the heap.
// now, imagine that the MyObject has an int field.
myObject.intField = 10; // as the contents of myObject are on the heap, the intField is on the heap.


If you use unsafe code you can check the real size of objects by using the sizeof() operator. It will show you how many bytes such object will occupy. If it is a value type, that means how many bytes it will occupy where it is declared (if declared locally, it will be in stack... if declared inside another class, that will means how many bytes it will add to the size of instances of that class).

And to explain your question about Name and Salary.
If you have a class with both Name and Salary, the contents of such class will always be on the heap.
So, you will have:
Name = some address... 4 or 8 bytes (depending if the computer is 32 or 64 bits)
Salary = (if it is an int, then 4 bytes).

And that "some address" will in fact be where the "keith" object is contained.
There is where an important factor happens:
Imagine that you have 2 instances of your type that has name and salary, but both pointing to the same name.

Considering a 64 bits computer, each instance will have the normal object header (I think it is 16 bytes) + a string reference (8 bytes) + an int (4 bytes).
That is: 28 for each instance * 2 = 56.
But you will have "keith" only once in memory.
Again, this should be 16 + the length of the string * 2 + some info used by the string itself (I think it is only the hashcode, but I am not sure). That is: 16 + 10 + 4. Or 30 bytes only to contain "keith" in memory.

Now, if you have 100 references to "keith", the string reference will always stay at 8 bytes... so, 100 references = 800 bytes. But the string is only once in memory. Much better than having 30 * 100 (or 3000 bytes) for the strings.

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.