Click here to Skip to main content
15,910,471 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: ANSI compliant XML Parser? Pin
Paul Selormey10-Mar-03 4:11
Paul Selormey10-Mar-03 4:11 
GeneralSave increment filename ... Pin
macmac386-Mar-03 3:39
macmac386-Mar-03 3:39 
GeneralRe: Save increment filename ... Pin
Paul Selormey10-Mar-03 0:47
Paul Selormey10-Mar-03 0:47 
GeneralAspireing c++ programmer (doesn't know Jack atm) Question Pin
Caden1-Mar-03 9:56
Caden1-Mar-03 9:56 
GeneralRe: Aspireing c++ programmer (doesn't know Jack atm) Question Pin
Paul Selormey2-Mar-03 23:47
Paul Selormey2-Mar-03 23:47 
GeneralRe: Aspireing c++ programmer (doesn't know Jack atm) Question Pin
Caden3-Mar-03 8:06
Caden3-Mar-03 8:06 
GeneralCreating objects on stack Pin
VizOne28-Feb-03 6:05
VizOne28-Feb-03 6:05 
GeneralRe: Creating objects on stack Pin
Jeff J1-Mar-03 16:26
Jeff J1-Mar-03 16:26 
Hello Andre,

VizOne wrote:
...is the C# version creating the object on
the heap or the stack?


As you suspected, the C# version is allocating on the heap, which is what the 'newobj' IL instruction normally does. So, the two pieces of code are not equivalent, and is partly why the instructions differ so.

The MC++ bit is dealing with a stack object, and even more importantly, is returning a copy of the object, not just a pointer (object reference in .Net lingo) to it. The 'ldobj' instruction verifies this, and I think a large part of the performance difference. Not only is the __value object initialised (initobj Cpp.MyStruct), but it's address is repeatedly pushed onto the stack (ldloca.s V_0) for various ops.

So the address of the static struct is loaded, it's initialised, the address is again loaded, constant params loaded, the ctor called, the object's address loaded yet again, then an entire copy made before returning. I can see why performance was bad.

However, I'm thinking the number of ops is not the most reliable way to gauge performance here. In particular, newobj does a lot for a single instruction, including runtime allocation on the GC heap, initialising, and then calling the ctor. Admittedly GC heap allocation is designed to be very fast, and nearly as fast as stack allocation, but the C# code does not make a copy. I suspect that's the biggest factor.

I'm curious if the code was optimised during compile, as that might make a significant difference. You have me digging deeper into this one, so I'll post back if I come up with anything more. I'll try making the MC++ and C# functions both return copies and pointers. Shame on you for stimulating my attrophied neurons! Wink | ;) Interesting stuff.

Cheers
GeneralRe: Creating objects on stack Pin
Paul Selormey2-Mar-03 23:40
Paul Selormey2-Mar-03 23:40 
GeneralRe: Creating objects on stack Pin
Jeff J3-Mar-03 11:49
Jeff J3-Mar-03 11:49 
GeneralRe: Creating objects on stack Pin
Jeff J3-Mar-03 11:43
Jeff J3-Mar-03 11:43 
GeneralRe: Creating objects on stack Pin
Paul Selormey3-Mar-03 23:47
Paul Selormey3-Mar-03 23:47 
GeneralRe: Creating objects on stack Pin
VizOne10-Mar-03 1:45
VizOne10-Mar-03 1:45 
GeneralRe: Creating objects on stack Pin
Paul Selormey9-Mar-03 17:07
Paul Selormey9-Mar-03 17:07 
GeneralMixins and __gc Pin
-=jarl=-27-Feb-03 3:59
-=jarl=-27-Feb-03 3:59 
GeneralRe: Mixins and __gc Pin
Paul Selormey27-Feb-03 22:11
Paul Selormey27-Feb-03 22:11 
GeneralRe: Mixins and __gc Pin
-=jarl=-6-Mar-03 1:14
-=jarl=-6-Mar-03 1:14 
GeneralHandles and pointers... Pin
-=jarl=-26-Feb-03 7:28
-=jarl=-26-Feb-03 7:28 
GeneralRe: Handles and pointers... Pin
Jeff J26-Feb-03 16:46
Jeff J26-Feb-03 16:46 
GeneralRe: Handles and pointers... Pin
-=jarl=-26-Feb-03 23:19
-=jarl=-26-Feb-03 23:19 
GeneralManaged and Unmanaged structures Pin
-=jarl=-26-Feb-03 6:55
-=jarl=-26-Feb-03 6:55 
GeneralRe: Managed and Unmanaged structures Pin
-=jarl=-26-Feb-03 6:58
-=jarl=-26-Feb-03 6:58 
GeneralRe: Managed and Unmanaged structures Pin
Paul Selormey26-Feb-03 13:51
Paul Selormey26-Feb-03 13:51 
GeneralRe: Managed and Unmanaged structures Pin
-=jarl=-26-Feb-03 23:16
-=jarl=-26-Feb-03 23:16 
GeneralRe: Managed and Unmanaged structures Pin
Paul Selormey27-Feb-03 0:20
Paul Selormey27-Feb-03 0:20 

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.