Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Difference between IJW and #pragma unmanaged ?

Difference between IJW and #pragma unmanaged ?

Scheduled Pinned Locked Moved Managed C++/CLI
c++question
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anti AS
    wrote on last edited by
    #1

    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??

    N 1 Reply Last reply
    0
    • A anti AS

      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??

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • N Nish Nishant

        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

        A Offline
        A Offline
        anti AS
        wrote on last edited by
        #3

        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 with printf() so (as i think) printf() will be compiled as native??So why I need to use #pragma umanaged directive.

        N 1 Reply Last reply
        0
        • A anti AS

          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 with printf() so (as i think) printf() will be compiled as native??So why I need to use #pragma umanaged directive.

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          The call to printf will be emitted via msil. The printf method itself will execute as native code (there will be a managed to unmanaged jump during execution). Now instead of printf, assume you were calling your own global function Foo. Now if you did not put Foo'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 think Foo is a time-intensive function.

          Regards, Nish


          Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

          A 1 Reply Last reply
          0
          • N Nish Nishant

            The call to printf will be emitted via msil. The printf method itself will execute as native code (there will be a managed to unmanaged jump during execution). Now instead of printf, assume you were calling your own global function Foo. Now if you did not put Foo'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 think Foo is a time-intensive function.

            Regards, Nish


            Latest article: Code Project Posts Analyzer for Windows Phone 7 My technology blog: voidnish.wordpress.com

            A Offline
            A Offline
            anti AS
            wrote on last edited by
            #5

            :thumbsup: Great man... It is more clear now. Thank you.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups