Click here to Skip to main content
15,890,506 members
Home / Discussions / C#
   

C#

 
GeneralRe: TFS Workitem type task Save failed. Pin
Dave Kreskowiak28-May-15 1:22
mveDave Kreskowiak28-May-15 1:22 
QuestionHow to calculate Size of a variable at runtime ? Not the datatype size. Pin
Gyana_Ranjan Dash26-May-15 21:14
Gyana_Ranjan Dash26-May-15 21:14 
AnswerRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
Richard MacCutchan26-May-15 21:51
mveRichard MacCutchan26-May-15 21:51 
AnswerRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
Simon_Whale26-May-15 22:01
Simon_Whale26-May-15 22:01 
AnswerRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
OriginalGriff26-May-15 23:49
mveOriginalGriff26-May-15 23:49 
GeneralRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
Gyana_Ranjan Dash27-May-15 1:10
Gyana_Ranjan Dash27-May-15 1:10 
GeneralRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
Richard Deeming27-May-15 1:20
mveRichard Deeming27-May-15 1:20 
GeneralRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
OriginalGriff27-May-15 1:23
mveOriginalGriff27-May-15 1:23 
This is where is starts to get complicated...

Because a Char is not the same everywhere! Laugh | :laugh:

'A' is a char - so it will normally return 2 because a Unicode character takes two bytes (an ASCII character takes one, but nearly all the time in .NET you are dealing with Unicode values)
So the sizeof(char) returns 2 because it needs two bytes of managed memory to store each char.

When you use Marshalling however, it isn't dealing with Managed memory, so it doesn't use Unicode - it uses ASCII instead. Because Marshalling is all about getting ready to talk to external non-NET applications, it can't just pass managed memory directly - because it might have to move it while the other application is using it - so it will effectively prepare a copy of the data in ASCII, because that is the older character standard that most apps used pre-NET.

So sizeof will give you the Managed size - 2
and Marshall.SizeOf gives you the unmanaged size - 1
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
Gyana_Ranjan Dash27-May-15 19:59
Gyana_Ranjan Dash27-May-15 19:59 
GeneralRe: How to calculate Size of a variable at runtime ? Not the datatype size. Pin
harold aptroot27-May-15 2:58
harold aptroot27-May-15 2:58 
Questionwhy no edit-flag at design-time, no compile-time error on this code abomination ? Pin
BillWoodruff26-May-15 10:48
professionalBillWoodruff26-May-15 10:48 
AnswerRe: why no edit-flag at design-time, no compile-time error on this code abomination ? Pin
Sascha Lefèvre26-May-15 11:17
professionalSascha Lefèvre26-May-15 11:17 
QuestionC# -> PHP/MYSQL Pin
Zell Kennedy26-May-15 4:02
Zell Kennedy26-May-15 4:02 
AnswerRe: C# -> PHP/MYSQL Pin
Bernhard Hiller26-May-15 6:36
Bernhard Hiller26-May-15 6:36 
GeneralRe: C# -> PHP/MYSQL Pin
Zell Kennedy26-May-15 7:30
Zell Kennedy26-May-15 7:30 
QuestionProblem Faced when perform row grouping in excel using c# Pin
Member 1130300726-May-15 2:18
Member 1130300726-May-15 2:18 
QuestionDifference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Gyana_Ranjan Dash25-May-15 20:26
Gyana_Ranjan Dash25-May-15 20:26 
AnswerRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
OriginalGriff25-May-15 20:46
mveOriginalGriff25-May-15 20:46 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Agent__00725-May-15 22:43
professionalAgent__00725-May-15 22:43 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Alan N25-May-15 23:22
Alan N25-May-15 23:22 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Agent__00725-May-15 23:56
professionalAgent__00725-May-15 23:56 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Gyana_Ranjan Dash26-May-15 21:08
Gyana_Ranjan Dash26-May-15 21:08 
GeneralRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# Pin
Armugam Indrani28-May-15 22:48
professionalArmugam Indrani28-May-15 22:48 
AnswerRe: Difference Between Equality Operator ( ==) and .Equals() Method in C# PinPopular
harold aptroot26-May-15 1:02
harold aptroot26-May-15 1:02 
QuestionDataRelation problem Pin
Supratik De25-May-15 6:35
Supratik De25-May-15 6:35 

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.