Difference between IJW and #pragma unmanaged ?
-
Hi guys In C++/CLI what is the difference between using the concept of IJW (It Just Works) and using pragma directive as following:
#pragma managed(push,off)
UnmanagedFunc(){
…native code …
}
#pragma managed(pop)Does IJW is enabled automatically (so just need to write our native code) or we need to do something to make it works..?? In other mean, what is the advantage of IJW over using pragma directive or the other way around??
-
Hi guys In C++/CLI what is the difference between using the concept of IJW (It Just Works) and using pragma directive as following:
#pragma managed(push,off)
UnmanagedFunc(){
…native code …
}
#pragma managed(pop)Does IJW is enabled automatically (so just need to write our native code) or we need to do something to make it works..?? In other mean, what is the advantage of IJW over using pragma directive or the other way around??
IJW is just a term they used back in 2003/2004 to talk about how the managed-unmanaged transitions and marshaling were smoothly handled for you by the compiler. No one uses the term these days, and instead people just say C++ interop to refer to anything where mixed-mode code comes into play.
#pragma unmanaged
is a pre-compiler directive that tells the compiler that any code in that block must be compiled natively (meaning no msil at all). It's mostly used to ensure that frequently used code is compiled for better performance (which usually implies native code generation).Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
IJW is just a term they used back in 2003/2004 to talk about how the managed-unmanaged transitions and marshaling were smoothly handled for you by the compiler. No one uses the term these days, and instead people just say C++ interop to refer to anything where mixed-mode code comes into play.
#pragma unmanaged
is a pre-compiler directive that tells the compiler that any code in that block must be compiled natively (meaning no msil at all). It's mostly used to ensure that frequently used code is compiled for better performance (which usually implies native code generation).Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
Thanx Nish If I use standard C function inside CPP/CLI code .. like for example:
ManagedFunction(){
..... Managed Code .....
..... Managed Code .....
printf("I am standard C function!\n");
..... Managed Code .....
..... Managed Code .....
}Does MSIL do something with the
printf()
function! (Notice that i did NOT use#pragma umanaged
directive!) If MSIL will do nothing withprintf()
so (as i think)printf()
will be compiled as native??So why I need to use#pragma umanaged
directive. -
Thanx Nish If I use standard C function inside CPP/CLI code .. like for example:
ManagedFunction(){
..... Managed Code .....
..... Managed Code .....
printf("I am standard C function!\n");
..... Managed Code .....
..... Managed Code .....
}Does MSIL do something with the
printf()
function! (Notice that i did NOT use#pragma umanaged
directive!) If MSIL will do nothing withprintf()
so (as i think)printf()
will be compiled as native??So why I need to use#pragma umanaged
directive.The call to
printf
will be emitted via msil. Theprintf
method itself will execute as native code (there will be a managed to unmanaged jump during execution). Now instead ofprintf
, assume you were calling your own global functionFoo
. Now if you did not putFoo
's definition in a#pragma unmanaged
block,Foo
itself will be compiled as msil. That's a scenario where you'd actually want to use#pragma unmanaged
, particularly if you thinkFoo
is a time-intensive function.Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com
-
The call to
printf
will be emitted via msil. Theprintf
method itself will execute as native code (there will be a managed to unmanaged jump during execution). Now instead ofprintf
, assume you were calling your own global functionFoo
. Now if you did not putFoo
's definition in a#pragma unmanaged
block,Foo
itself will be compiled as msil. That's a scenario where you'd actually want to use#pragma unmanaged
, particularly if you thinkFoo
is a time-intensive function.Regards, Nish
Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com