Click here to Skip to main content
15,914,416 members
Home / Discussions / C#
   

C#

 
GeneralRe: 'Locking' entire folder Pin
kshet263-Jan-05 9:36
kshet263-Jan-05 9:36 
GeneralRe: 'Locking' entire folder Pin
Dave Kreskowiak3-Jan-05 11:07
mveDave Kreskowiak3-Jan-05 11:07 
GeneralRe: 'Locking' entire folder Pin
kshet263-Jan-05 17:13
kshet263-Jan-05 17:13 
GeneralRe: 'Locking' entire folder Pin
Dave Kreskowiak4-Jan-05 16:50
mveDave Kreskowiak4-Jan-05 16:50 
Generalmousewheel!!! Pin
osto2-Jan-05 18:06
osto2-Jan-05 18:06 
GeneralPoll sample Pin
anandg_g2-Jan-05 17:04
anandg_g2-Jan-05 17:04 
GeneralTrouble with asynch sockets...program not exiting from taskmanager list Pin
FocusedWolf2-Jan-05 16:51
FocusedWolf2-Jan-05 16:51 
GeneralPassing Value Types by Reference Pin
paulsawyer2-Jan-05 16:44
paulsawyer2-Jan-05 16:44 
Last month I asked a question on this forum about the relative efficiency of passing value types that were member of reference types or member of arrays as parameters to functions using ref and out. My original question was whether or not it would be more efficient to pass a large structure that was a member of a class using ref even if I didn’t need to make modifications to the stuct t needed to be passed back to the calling routine. In C or C++ it would be more efficient to pass by address and Jeffrey Richter in his excellent book: “Applied Microsoft .NET Framework Programming” also says that it is more efficient in to pass large value types using ref in C# (although he isn’t specifically referring to value types that are embedded in reference types). Anyway, the answer that I got back on this forum was that passing a value type that was embedded in a reference type using ref or out would require boxing the value type which of course would be very inefficient. I was also told that if I was going to pass something around a lot that it should be class rather than a struct. And I was also told that large objects should also be classes for efficiency.

Anyway, I am hoping to get some more opinions on this. I checked several C# books and searched the internet and I haven’t found anyone saying that passing a struct that is embedded in a class using ref would cause the struct to be boxed. Also I have looked at some IL code of that circumstance and I don’t see any Box instructions. Rather I see a ldflda instruction which: “Finds the address of a field in the object whose reference is currently on the evaluation stack” which sure looks to me like it is passing the address of the struct. If C# really does pass an address, that would be the more efficient way to pass a large struct. So from my understanding, it looks like passing structs embedded in classes using ref does not cause boxing therefore, I still don’t have any reason to believe that it would be more efficient to make large structs classes or that large objects that need to passed around a lot should be classes. Can anyone enlighten me further about this? Also, assuming that C# really does pass structs that are embedded in classes or arrays using ref by passing the address of the struct, how does C# get around not having to pin the enclosing class or array to prevent it from being moved by the garbage collector and there by making the passed address invalid? I know I am not supposed to think about addresses anymore but I really do need to figure out what the most efficient way of passing large structs around or if I really should make them classes – even though they don’t need to be classes for any other reason. Thanks so much for the help.


Paul Sawyer
GeneralSerialization for an ArrayList Pin
zecodela2-Jan-05 15:46
zecodela2-Jan-05 15:46 
GeneralRe: Serialization for an ArrayList Pin
Robert Rohde2-Jan-05 18:38
Robert Rohde2-Jan-05 18:38 
GeneralRe: Serialization for an ArrayList Pin
zecodela3-Jan-05 14:37
zecodela3-Jan-05 14:37 
GeneralCrystal Reports to pdf Pin
2-Jan-05 15:45
suss2-Jan-05 15:45 
GeneralRe: Crystal Reports to pdf Pin
jareddavies3-Jan-05 12:57
jareddavies3-Jan-05 12:57 
GeneralWANT REAL TIME MOUSE COORD Pin
...---...2-Jan-05 11:28
...---...2-Jan-05 11:28 
GeneralRe: WANT REAL TIME MOUSE COORD Pin
DavidNohejl2-Jan-05 12:08
DavidNohejl2-Jan-05 12:08 
GeneralScrollbar maximum value problem Pin
Andrew Stampor2-Jan-05 11:11
Andrew Stampor2-Jan-05 11:11 
GeneralRe: Scrollbar maximum value problem Pin
Andrew Stampor2-Jan-05 13:41
Andrew Stampor2-Jan-05 13:41 
GeneralQuestion about Socket Flags Pin
MasudM2-Jan-05 9:24
MasudM2-Jan-05 9:24 
GeneralGravitating guns... Pin
Jacob Buys2-Jan-05 5:58
Jacob Buys2-Jan-05 5:58 
QuestionHow can I encapsulate my program? Pin
gyokusei2-Jan-05 5:16
gyokusei2-Jan-05 5:16 
AnswerRe: How can I encapsulate my program? Pin
Identity Undisclosed2-Jan-05 8:12
Identity Undisclosed2-Jan-05 8:12 
Generalturbo c Pin
Alvin142-Jan-05 4:17
Alvin142-Jan-05 4:17 
GeneralRe: turbo c Pin
Alex Korchemniy2-Jan-05 6:01
Alex Korchemniy2-Jan-05 6:01 
GeneralRe: turbo c Pin
Matt Gerrans3-Jan-05 13:24
Matt Gerrans3-Jan-05 13:24 
GeneralNamespace Extensions for Windows Explorer Pin
GeloSoft2-Jan-05 2:50
GeloSoft2-Jan-05 2:50 

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.