Forward declarations and #pragma managed/unmanaged

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gustavo L. Fabro

    #1

    Forward declarations and #pragma managed/unmanaged

    Greetings!

    Going directly to the point:

    myclass.h:
    //--------------------------------------

    #pragma managed

    //Forward declaration
    class AnotherClass;

    #pragma unmanaged

    class MyClass
    {
    public:
    void func1(AnotherCl ass* ptr);
    }

    Will this '#pragma managed' before 'class AnotherClass' have any effect at
    all on my native class? I know the forwad declaration only puts the symbol's
    name under the symbols table, but I was wondering if, being defined under
    'managed' setting, this symbol would have any thunking layers or anything
    like that that would make it's access slower.

    Thanks,

    Fabro



  • Carl Daniel [VC++ MVP]

    #2
    Re: Forward declarations and #pragma managed/unmanaged

    Gustavo L. Fabro wrote:[color=blue]
    > Greetings!
    >
    > Going directly to the point:
    >
    > myclass.h:
    > //--------------------------------------
    >
    > #pragma managed
    >
    > //Forward declaration
    > class AnotherClass;
    >
    > #pragma unmanaged
    >
    > class MyClass
    > {
    > public:
    > void func1(AnotherCl ass* ptr);
    > }
    >
    > Will this '#pragma managed' before 'class AnotherClass' have any
    > effect at all on my native class? I know the forwad declaration only
    > puts the symbol's name under the symbols table, but I was wondering
    > if, being defined under 'managed' setting, this symbol would have any
    > thunking layers or anything like that that would make it's access
    > slower.[/color]

    Based on a very simply experiment, it doesn't appear to make any difference.
    What matters is whether #pragma managed is in effect where the class
    definition appears.

    <code>
    #pragma managed

    //Forward declaration
    class AnotherClass;

    #pragma unmanaged

    class MyClass
    {
    public:
    void func1(AnotherCl ass* ptr) {}
    };

    #pragma unmanaged // 1

    class AnotherClass
    {
    public:
    void f() {}
    };
    </code>

    If the line at //1 is #pragma unmanaged, the resulting .obj looks identical
    to that produced if // 1 is deleted. It // 1 is #pragma managed,
    AnotherClass::f () is emitted as managed code.

    -cd


    Comment

    • Gustavo L. Fabro

      #3
      Re: Forward declarations and #pragma managed/unmanaged

      Hmmm

      I took your idea and compiled these files

      #1

      #pragma managed
      class AnotherClass;
      #pragma unmanaged

      class MyClass
      {
      public:
      void func1(AnotherCl ass* ptr);
      }

      #2

      #pragma unmanaged
      class AnotherClass;
      #pragma unmanaged

      class MyClass
      {
      public:
      void func1(AnotherCl ass* ptr);
      }

      The obj files have the same size but are different. But that doesn't tell
      *me* much, because If I compile the same file twice, different (binary
      speaking) obj files will be created too.

      Fabro


      Comment

      • Carl Daniel [VC++ MVP]

        #4
        Re: Forward declarations and #pragma managed/unmanaged

        Gustavo L. Fabro wrote:[color=blue]
        > Hmmm
        >
        > I took your idea and compiled these files
        >
        > #1
        >
        > #pragma managed
        > class AnotherClass;
        > #pragma unmanaged
        >
        > class MyClass
        > {
        > public:
        > void func1(AnotherCl ass* ptr);
        > }
        >
        > #2
        >
        > #pragma unmanaged
        > class AnotherClass;
        > #pragma unmanaged
        >
        > class MyClass
        > {
        > public:
        > void func1(AnotherCl ass* ptr);
        > }
        >
        > The obj files have the same size but are different. But that doesn't
        > tell *me* much, because If I compile the same file twice, different
        > (binary
        > speaking) obj files will be created too.[/color]

        Use dumpbin /all on the .OBJ files to see the internals. I didn't do a very
        thorough examination, but at the level I did look, it appeared that no
        significant changes to the file were made. In your example, there's no code
        being generated at all, so I think you need to embelish the test case just a
        bit to make it meaningful.

        -cd


        Comment

        • Gustavo L. Fabro

          #5
          Re: Forward declarations and #pragma managed/unmanaged

          Hmmm

          I took your idea and compiled these files

          #1

          #pragma managed
          class AnotherClass;
          #pragma unmanaged

          class MyClass
          {
          public:
          void func1(AnotherCl ass* ptr);
          }

          #2

          #pragma unmanaged
          class AnotherClass;
          #pragma unmanaged

          class MyClass
          {
          public:
          void func1(AnotherCl ass* ptr);
          }

          The obj files have the same size but are different. But that doesn't tell
          *me* much, because If I compile the same file twice, different (binary
          speaking) obj files will be created too.

          Fabro


          Comment

          • Carl Daniel [VC++ MVP]

            #6
            Re: Forward declarations and #pragma managed/unmanaged

            Gustavo L. Fabro wrote:[color=blue]
            > Hmmm
            >
            > I took your idea and compiled these files
            >
            > #1
            >
            > #pragma managed
            > class AnotherClass;
            > #pragma unmanaged
            >
            > class MyClass
            > {
            > public:
            > void func1(AnotherCl ass* ptr);
            > }
            >
            > #2
            >
            > #pragma unmanaged
            > class AnotherClass;
            > #pragma unmanaged
            >
            > class MyClass
            > {
            > public:
            > void func1(AnotherCl ass* ptr);
            > }
            >
            > The obj files have the same size but are different. But that doesn't
            > tell *me* much, because If I compile the same file twice, different
            > (binary
            > speaking) obj files will be created too.[/color]

            Use dumpbin /all on the .OBJ files to see the internals. I didn't do a very
            thorough examination, but at the level I did look, it appeared that no
            significant changes to the file were made. In your example, there's no code
            being generated at all, so I think you need to embelish the test case just a
            bit to make it meaningful.

            -cd


            Comment

            Working...