473,722 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Mixed mode CLI problem/query

Hi,

I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid the usage of old style COM, my alternative is to expose my unmanaged interface through the CLI, to achieve that I have created a mixed mode DLL in which my unmanaged class are defined.
When referencing the DLL just described in another mixed mode EXE I can see the unmanaged methods through the 'Object browser' BUT, I can't reference them through code, the namespace of the DLL is not recognised....
When using a managed C# EXE to reference the unmanaged CLI assembly the namespace is identified BUT the contained objects are not...
Is it possible to expose unmanaged interface through the CLI??? is it possible to reference this type of interface through another mixed mode assembly? will VS2005 support this kind of functionality?

Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have created:
namespace Unmanaged
{
__nogc interface IBlockAllocator ;
__nogc interface IDataBlock
{
virtual HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize, void *pExArg) = 0;
virtual IBlockAllocator *Allocator()= 0;
virtual BYTE *Pointer()= 0;
virtual const DWORD Size()= 0;
virtual LONG AddRef() =0;
virtual LONG Release()= 0;
virtual void Dispose()= 0;
};

__nogc class CDataBlock : public IDataBlock
{
protected:
DWORD m_dwSize;
LONG m_lRefCount;
BYTE *m_pData;
IBlockAllocator *m_pAlloc;
public:
IBlockAllocator *Allocator() { return m_pAlloc;}
BYTE *Pointer() { return m_pData;}
const DWORD Size() { return m_dwSize;}
LONG AddRef() { return InterlockedIncr ement(&m_lRefCo unt); }
LONG Release()
{
if(0 != InterlockedDecr ement(&m_lRefCo unt))
return m_lRefCount;
m_pAlloc->ReturnToCache( this);
return 0;
}
void Dispose() { delete this; }
HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize, void *pExArg = 0)
{
m_pAlloc = pAlloc;
m_dwSize = m_pAlloc->GetBlockSize() ;
m_pData = new BYTE[m_dwSize];
};
CDataBlock() : m_lRefCount(0)
{
}
~CDataBlock()
{
delete m_pData;
m_pData = 0;
m_pAlloc = 0;
}
};
};// Unmanaged

Nadav
http://www.ddevel.com
Nov 17 '05 #1
8 1998
Create your methods as static members of a __value or __gc class. Then you
will be able to access them for the managed side.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I am writing a performence critical application, this require me to stick
to unmanaged C++ as performance is much better using unmanaged C++ ( about
33% better ), Still, I am trying to avoid the usage of old style COM, my
alternative is to expose my unmanaged interface through the CLI, to
achieve that I have created a mixed mode DLL in which my unmanaged class
are defined.
When referencing the DLL just described in another mixed mode EXE I can
see the unmanaged methods through the 'Object browser' BUT, I can't
reference them through code, the namespace of the DLL is not
recognised....
When using a managed C# EXE to reference the unmanaged CLI assembly the
namespace is identified BUT the contained objects are not...
Is it possible to expose unmanaged interface through the CLI??? is it
possible to reference this type of interface through another mixed mode
assembly? will VS2005 support this kind of functionality?

Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
created:
namespace Unmanaged
{
__nogc interface IBlockAllocator ;
__nogc interface IDataBlock
{
virtual HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize,
void *pExArg) = 0;
virtual IBlockAllocator *Allocator()= 0;
virtual BYTE *Pointer()= 0;
virtual const DWORD Size()= 0;
virtual LONG AddRef() =0;
virtual LONG Release()= 0;
virtual void Dispose()= 0;
};

__nogc class CDataBlock : public IDataBlock
{
protected:
DWORD m_dwSize;
LONG m_lRefCount;
BYTE *m_pData;
IBlockAllocator *m_pAlloc;
public:
IBlockAllocator *Allocator() { return m_pAlloc;}
BYTE *Pointer() { return m_pData;}
const DWORD Size() { return m_dwSize;}
LONG AddRef() { return InterlockedIncr ement(&m_lRefCo unt); }
LONG Release()
{
if(0 != InterlockedDecr ement(&m_lRefCo unt))
return m_lRefCount;
m_pAlloc->ReturnToCache( this);
return 0;
}
void Dispose() { delete this; }
HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize, void
*pExArg = 0)
{
m_pAlloc = pAlloc;
m_dwSize = m_pAlloc->GetBlockSize() ;
m_pData = new BYTE[m_dwSize];
};
CDataBlock() : m_lRefCount(0)
{
}
~CDataBlock()
{
delete m_pData;
m_pData = 0;
m_pAlloc = 0;
}
};
};// Unmanaged

Nadav
http://www.ddevel.com

Nov 17 '05 #2
Hi Ronald, Thanks for your response, Still, I have some open issues:
1. Is it possible to define an unmanaged class ( not static ) and expose it using CLI in a way that it would be able to be accessed from managed and unmanaged code? ( i didn't find any in the current VS version and in VS2005.Beta ), My alternative is to use COM which I would really like to avoid...
2. I Did several performance tests with VS2005.Beta, unmanaged C++ if far more efficient then C#, one of the tests I have done involved mixed mode C++ ( using VS2005 ), I have wrapped my (efficient) unmanaged project with a managed wrapper, running this project result performance of about 90 Precent of the original unmanaged project, note that the managed code used merely as an entry point to execute the unmanaged code ( e.g. MyObj->RunUnmanaged () ), why does performance is lost? it seems that loading the CLR it-self causes a performance loss...
2.1. Some words of the test application: it is a winsock app that use IOCompletion port for async IO.

P.S.
How do the guys in Microsoft treat this kind of problems? What language is used for performance critical modules ( I guess it is unmanaged C++ ) that should interact with managed assemblies? What would be the best way of implementing a performance critical module ( CLI, COM, ... ) that should interact with managed code ?

Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Create your methods as static members of a __value or __gc class. Then you
will be able to access them for the managed side.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I am writing a performence critical application, this require me to stick
to unmanaged C++ as performance is much better using unmanaged C++ ( about
33% better ), Still, I am trying to avoid the usage of old style COM, my
alternative is to expose my unmanaged interface through the CLI, to
achieve that I have created a mixed mode DLL in which my unmanaged class
are defined.
When referencing the DLL just described in another mixed mode EXE I can
see the unmanaged methods through the 'Object browser' BUT, I can't
reference them through code, the namespace of the DLL is not
recognised....
When using a managed C# EXE to reference the unmanaged CLI assembly the
namespace is identified BUT the contained objects are not...
Is it possible to expose unmanaged interface through the CLI??? is it
possible to reference this type of interface through another mixed mode
assembly? will VS2005 support this kind of functionality?

Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
created:
namespace Unmanaged
{
__nogc interface IBlockAllocator ;
__nogc interface IDataBlock
{
virtual HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize,
void *pExArg) = 0;
virtual IBlockAllocator *Allocator()= 0;
virtual BYTE *Pointer()= 0;
virtual const DWORD Size()= 0;
virtual LONG AddRef() =0;
virtual LONG Release()= 0;
virtual void Dispose()= 0;
};

__nogc class CDataBlock : public IDataBlock
{
protected:
DWORD m_dwSize;
LONG m_lRefCount;
BYTE *m_pData;
IBlockAllocator *m_pAlloc;
public:
IBlockAllocator *Allocator() { return m_pAlloc;}
BYTE *Pointer() { return m_pData;}
const DWORD Size() { return m_dwSize;}
LONG AddRef() { return InterlockedIncr ement(&m_lRefCo unt); }
LONG Release()
{
if(0 != InterlockedDecr ement(&m_lRefCo unt))
return m_lRefCount;
m_pAlloc->ReturnToCache( this);
return 0;
}
void Dispose() { delete this; }
HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize, void
*pExArg = 0)
{
m_pAlloc = pAlloc;
m_dwSize = m_pAlloc->GetBlockSize() ;
m_pData = new BYTE[m_dwSize];
};
CDataBlock() : m_lRefCount(0)
{
}
~CDataBlock()
{
delete m_pData;
m_pData = 0;
m_pAlloc = 0;
}
};
};// Unmanaged

Nadav
http://www.ddevel.com


Nov 17 '05 #3
Hi Ronald, Thanks for your response, Still, I have some open issues:
1. Is it possible to define an unmanaged class ( not static ) and expose it using CLI in a way that it would be able to be accessed from managed and unmanaged code? ( i didn't find any in the current VS version and in VS2005.Beta ), My alternative is to use COM which I would really like to avoid...
2. I Did several performance tests with VS2005.Beta, unmanaged C++ if far more efficient then C#, one of the tests I have done involved mixed mode C++ ( using VS2005 ), I have wrapped my (efficient) unmanaged project with a managed wrapper, running this project result performance of about 90% of the original unmanaged project, note that the managed code used merely as an entry point to execute the unmanaged code ( e.g. MyObj->RunUnmanaged () ), why does performance is lost? it seems that loading the CLR it-self causes a performance loss...
2.1. Some words of the test application: it is a winsock app that use IOCompletion port for async IO.

P.S.
How do the guys in Microsoft treat this kind of problems? What language is used for performance critical modules ( I guess it is unmanaged C++ ) that should interact with managed assemblies? What would be the best way of implementing a performance critical module ( CLI, COM, ... ) that should interact with managed code ?

Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Create your methods as static members of a __value or __gc class. Then you
will be able to access them for the managed side.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I am writing a performence critical application, this require me to stick
to unmanaged C++ as performance is much better using unmanaged C++ ( about
33% better ), Still, I am trying to avoid the usage of old style COM, my
alternative is to expose my unmanaged interface through the CLI, to
achieve that I have created a mixed mode DLL in which my unmanaged class
are defined.
When referencing the DLL just described in another mixed mode EXE I can
see the unmanaged methods through the 'Object browser' BUT, I can't
reference them through code, the namespace of the DLL is not
recognised....
When using a managed C# EXE to reference the unmanaged CLI assembly the
namespace is identified BUT the contained objects are not...
Is it possible to expose unmanaged interface through the CLI??? is it
possible to reference this type of interface through another mixed mode
assembly? will VS2005 support this kind of functionality?

Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
created:
namespace Unmanaged
{
__nogc interface IBlockAllocator ;
__nogc interface IDataBlock
{
virtual HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize,
void *pExArg) = 0;
virtual IBlockAllocator *Allocator()= 0;
virtual BYTE *Pointer()= 0;
virtual const DWORD Size()= 0;
virtual LONG AddRef() =0;
virtual LONG Release()= 0;
virtual void Dispose()= 0;
};

__nogc class CDataBlock : public IDataBlock
{
protected:
DWORD m_dwSize;
LONG m_lRefCount;
BYTE *m_pData;
IBlockAllocator *m_pAlloc;
public:
IBlockAllocator *Allocator() { return m_pAlloc;}
BYTE *Pointer() { return m_pData;}
const DWORD Size() { return m_dwSize;}
LONG AddRef() { return InterlockedIncr ement(&m_lRefCo unt); }
LONG Release()
{
if(0 != InterlockedDecr ement(&m_lRefCo unt))
return m_lRefCount;
m_pAlloc->ReturnToCache( this);
return 0;
}
void Dispose() { delete this; }
HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize, void
*pExArg = 0)
{
m_pAlloc = pAlloc;
m_dwSize = m_pAlloc->GetBlockSize() ;
m_pData = new BYTE[m_dwSize];
};
CDataBlock() : m_lRefCount(0)
{
}
~CDataBlock()
{
delete m_pData;
m_pData = 0;
m_pAlloc = 0;
}
};
};// Unmanaged

Nadav
http://www.ddevel.com


Nov 17 '05 #4
Hi Ronald, Thanks for your response, Still, I have some open issues:
1. Is it possible to define an unmanaged class ( not static ) and expose it using CLI in a way that it would be able to be accessed from managed and unmanaged code? ( i didn't find any in the current VS version and in VS2005.Beta ), My alternative is to use COM which I would really like to avoid...
2. I Did several performance tests with VS2005.Beta, unmanaged C++ if far more efficient then C#, one of the tests I have done involved mixed mode C++ ( using VS2005 ), I have wrapped my (efficient) unmanaged project with a managed wrapper, running this project result performance of about 90% of the original unmanaged project, note that the managed code used merely as an entry point to execute the unmanaged code ( e.g. MyObj->RunUnmanaged () ), why does performance is lost? it seems that loading the CLR it-self causes a performance loss...
2.1. Some words of the test application: it is a winsock app that use IOCompletion port for async IO.

P.S.
How do the guys in Microsoft treat this kind of problems? What language is used for performance critical modules ( I guess it is unmanaged C++ ) that should interact with managed assemblies? What would be the best way of implementing a performance critical module ( CLI, COM, ... ) that should interact with managed code ?

Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Create your methods as static members of a __value or __gc class. Then you
will be able to access them for the managed side.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I am writing a performence critical application, this require me to stick
to unmanaged C++ as performance is much better using unmanaged C++ ( about
33% better ), Still, I am trying to avoid the usage of old style COM, my
alternative is to expose my unmanaged interface through the CLI, to
achieve that I have created a mixed mode DLL in which my unmanaged class
are defined.
When referencing the DLL just described in another mixed mode EXE I can
see the unmanaged methods through the 'Object browser' BUT, I can't
reference them through code, the namespace of the DLL is not
recognised....
When using a managed C# EXE to reference the unmanaged CLI assembly the
namespace is identified BUT the contained objects are not...
Is it possible to expose unmanaged interface through the CLI??? is it
possible to reference this type of interface through another mixed mode
assembly? will VS2005 support this kind of functionality?

Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
created:
namespace Unmanaged
{
__nogc interface IBlockAllocator ;
__nogc interface IDataBlock
{


Nov 17 '05 #5
Hi Ronald, Thanks for your response, Still, I have some open issues:
1. Is it possible to define an unmanaged class ( not static ) and expose it using CLI in a way that it would be able to be accessed from managed and unmanaged code? ( i didn't find any in the current VS version and in VS2005.Beta ), My alternative is to use COM which I would really like to avoid...
2. I Did several performance tests with VS2005.Beta, unmanaged C++ if far more efficient then C#, one of the tests I have done involved mixed mode C++ ( using VS2005 ), I have wrapped my (efficient) unmanaged project with a managed wrapper, running this project result performance of about 90% of the original unmanaged project, note that the managed code used merely as an entry point to execute the unmanaged code ( e.g. MyObj->RunUnmanaged () ), why does performance is lost? it seems that loading the CLR it-self causes a performance loss...
2.1. Some words of the test application: it is a winsock app that use IOCompletion port for async IO.

P.S.
How do the guys in Microsoft treat this kind of problems? What language is used for performance critical modules ( I guess it is unmanaged C++ ) that should interact with managed assemblies? What would be the best way of implementing a performance critical module ( CLI, COM, ... ) that should interact with managed code ?

Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Create your methods as static members of a __value or __gc class. Then you
will be able to access them for the managed side.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I am writing a performence critical application, this require me to stick
to unmanaged C++ as performance is much better using unmanaged C++ ( about
33% better ), Still, I am trying to avoid the usage of old style COM, my
alternative is to expose my unmanaged interface through the CLI, to
achieve that I have created a mixed mode DLL in which my unmanaged class
are defined.
When referencing the DLL just described in another mixed mode EXE I can
see the unmanaged methods through the 'Object browser' BUT, I can't
reference them through code, the namespace of the DLL is not
recognised....
When using a managed C# EXE to reference the unmanaged CLI assembly the
namespace is identified BUT the contained objects are not...
Is it possible to expose unmanaged interface through the CLI??? is it
possible to reference this type of interface through another mixed mode
assembly? will VS2005 support this kind of functionality?

Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
created:
namespace Unmanaged
{
__nogc interface IBlockAllocator ;
__nogc interface IDataBlock
{


Nov 17 '05 #6
inline.

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A8******** *************** ***********@mic rosoft.com...
Hi Ronald, Thanks for your response, Still, I have some open issues:
1. Is it possible to define an unmanaged class ( not static ) and expose
it using CLI in a way that it would be able to be accessed from managed
and unmanaged code? ( i didn't find any in the current VS version and in
VS2005.Beta ), My alternative is to use COM which I would really like to
avoid... No, it isn't in a practical sense of the word. I am not sure why you want to
avoid using a managed class though. That is a far superior mechanism to COM
in any way I could think of. AT least in the aspects of performance,
maintainability and ease of development.
2. I Did several performance tests with VS2005.Beta, unmanaged C++ if far
more efficient then C#, one of the tests I have done involved mixed mode
C++ ( using VS2005 ), I have wrapped my (efficient) unmanaged project with
a managed wrapper, running this project result performance of about 90% of
the original unmanaged project, note that the managed code used merely as
an entry point to execute the unmanaged code ( e.g.
MyObj->RunUnmanaged () ), why does performance is lost? it seems that
loading the CLR it-self causes a performance loss... If your API is very chatty (e.g. method executions only take a few to a few
hundreds of instructions) then the interop overhead could explain this. If
you are measuring only a very small timeframe and your measurement includes
startup (rather that steady state performance) that could indeed be an
explanation. If it is neither, I fear that only using a decent profiler will
get you closer to understanding where you are losing the 10% in performance.
2.1. Some words of the test application: it is a winsock app that use
IOCompletion port for async IO.

P.S.
How do the guys in Microsoft treat this kind of problems? What language is
used for performance critical modules ( I guess it is unmanaged C++ ) that
should interact with managed assemblies? What would be the best way of
implementing a performance critical module ( CLI, COM, ... ) that should
interact with managed code ? Internally the guidelines are to use C++ and not COM interop. COM interop is
used internally only to intercat with existing COM objects. We never create
new COM interfaces just to be able to use COM interop as the interaction
point.


Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Create your methods as static members of a __value or __gc class. Then
you
will be able to access them for the managed side.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
> Hi,
>
> I am writing a performence critical application, this require me to
> stick
> to unmanaged C++ as performance is much better using unmanaged C++ (
> about
> 33% better ), Still, I am trying to avoid the usage of old style COM,
> my
> alternative is to expose my unmanaged interface through the CLI, to
> achieve that I have created a mixed mode DLL in which my unmanaged
> class
> are defined.
> When referencing the DLL just described in another mixed mode EXE I can
> see the unmanaged methods through the 'Object browser' BUT, I can't
> reference them through code, the namespace of the DLL is not
> recognised....
> When using a managed C# EXE to reference the unmanaged CLI assembly the
> namespace is identified BUT the contained objects are not...
> Is it possible to expose unmanaged interface through the CLI??? is it
> possible to reference this type of interface through another mixed mode
> assembly? will VS2005 support this kind of functionality?
>
> Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
> created:
> namespace Unmanaged
> {
> __nogc interface IBlockAllocator ;
> __nogc interface IDataBlock
> {
> virtual HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD
> dwSize,
> void *pExArg) = 0;
> virtual IBlockAllocator *Allocator()= 0;
> virtual BYTE *Pointer()= 0;
> virtual const DWORD Size()= 0;
> virtual LONG AddRef() =0;
> virtual LONG Release()= 0;
> virtual void Dispose()= 0;
> };
>
> __nogc class CDataBlock : public IDataBlock
> {
> protected:
> DWORD m_dwSize;
> LONG m_lRefCount;
> BYTE *m_pData;
> IBlockAllocator *m_pAlloc;
> public:
> IBlockAllocator *Allocator() { return m_pAlloc;}
> BYTE *Pointer() { return m_pData;}
> const DWORD Size() { return m_dwSize;}
> LONG AddRef() { return InterlockedIncr ement(&m_lRefCo unt); }
> LONG Release()
> {
> if(0 != InterlockedDecr ement(&m_lRefCo unt))
> return m_lRefCount;
> m_pAlloc->ReturnToCache( this);
> return 0;
> }
> void Dispose() { delete this; }
> HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize, void
> *pExArg = 0)
> {
> m_pAlloc = pAlloc;
> m_dwSize = m_pAlloc->GetBlockSize() ;
> m_pData = new BYTE[m_dwSize];
> };
> CDataBlock() : m_lRefCount(0)
> {
> }
> ~CDataBlock()
> {
> delete m_pData;
> m_pData = 0;
> m_pAlloc = 0;
> }
> };
> };// Unmanaged
>
> Nadav
> http://www.ddevel.com


Nov 17 '05 #7
Hi Ronald, Thanks for your detailed responce, I would just like to clarify a thing: in youre responce you ve saied: "Internally the guidelines are to use C++ and not COM interop..." by saying 'the guidelines are to use C++' do you reffer to mixed mode C++? what is the guidlines for exposing an unmanaged code to a managed code?

Nadav
http://www.ddevel.com
"Ronald Laeremans [MSFT]" wrote:
inline.

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A8******** *************** ***********@mic rosoft.com...
Hi Ronald, Thanks for your response, Still, I have some open issues:
1. Is it possible to define an unmanaged class ( not static ) and expose
it using CLI in a way that it would be able to be accessed from managed
and unmanaged code? ( i didn't find any in the current VS version and in
VS2005.Beta ), My alternative is to use COM which I would really like to
avoid...

No, it isn't in a practical sense of the word. I am not sure why you want to
avoid using a managed class though. That is a far superior mechanism to COM
in any way I could think of. AT least in the aspects of performance,
maintainability and ease of development.
2. I Did several performance tests with VS2005.Beta, unmanaged C++ if far
more efficient then C#, one of the tests I have done involved mixed mode
C++ ( using VS2005 ), I have wrapped my (efficient) unmanaged project with
a managed wrapper, running this project result performance of about 90% of
the original unmanaged project, note that the managed code used merely as
an entry point to execute the unmanaged code ( e.g.
MyObj->RunUnmanaged () ), why does performance is lost? it seems that
loading the CLR it-self causes a performance loss...

If your API is very chatty (e.g. method executions only take a few to a few
hundreds of instructions) then the interop overhead could explain this. If
you are measuring only a very small timeframe and your measurement includes
startup (rather that steady state performance) that could indeed be an
explanation. If it is neither, I fear that only using a decent profiler will
get you closer to understanding where you are losing the 10% in performance.
2.1. Some words of the test application: it is a winsock app that use
IOCompletion port for async IO.

P.S.
How do the guys in Microsoft treat this kind of problems? What language is
used for performance critical modules ( I guess it is unmanaged C++ ) that
should interact with managed assemblies? What would be the best way of
implementing a performance critical module ( CLI, COM, ... ) that should
interact with managed code ?

Internally the guidelines are to use C++ and not COM interop. COM interop is
used internally only to intercat with existing COM objects. We never create
new COM interfaces just to be able to use COM interop as the interaction
point.


Nadav
http://www.ddevel.com

"Ronald Laeremans [MSFT]" wrote:
Create your methods as static members of a __value or __gc class. Then
you
will be able to access them for the managed side.

Ronald Laeremans
Visual C++ team

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
> Hi,
>
> I am writing a performence critical application, this require me to
> stick
> to unmanaged C++ as performance is much better using unmanaged C++ (
> about
> 33% better ), Still, I am trying to avoid the usage of old style COM,
> my
> alternative is to expose my unmanaged interface through the CLI, to
> achieve that I have created a mixed mode DLL in which my unmanaged
> class
> are defined.
> When referencing the DLL just described in another mixed mode EXE I can
> see the unmanaged methods through the 'Object browser' BUT, I can't
> reference them through code, the namespace of the DLL is not
> recognised....
> When using a managed C# EXE to reference the unmanaged CLI assembly the
> namespace is identified BUT the contained objects are not...
> Is it possible to expose unmanaged interface through the CLI??? is it
> possible to reference this type of interface through another mixed mode
> assembly? will VS2005 support this kind of functionality?
>
> Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
> created:
> namespace Unmanaged
> {
> __nogc interface IBlockAllocator ;
> __nogc interface IDataBlock
> {
> virtual HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD
> dwSize,
> void *pExArg) = 0;
> virtual IBlockAllocator *Allocator()= 0;
> virtual BYTE *Pointer()= 0;
> virtual const DWORD Size()= 0;
> virtual LONG AddRef() =0;
> virtual LONG Release()= 0;
> virtual void Dispose()= 0;
> };
>
> __nogc class CDataBlock : public IDataBlock
> {
> protected:
> DWORD m_dwSize;
> LONG m_lRefCount;
> BYTE *m_pData;
> IBlockAllocator *m_pAlloc;
> public:
> IBlockAllocator *Allocator() { return m_pAlloc;}
> BYTE *Pointer() { return m_pData;}
> const DWORD Size() { return m_dwSize;}
> LONG AddRef() { return InterlockedIncr ement(&m_lRefCo unt); }
> LONG Release()
> {
> if(0 != InterlockedDecr ement(&m_lRefCo unt))
> return m_lRefCount;
> m_pAlloc->ReturnToCache( this);
> return 0;
> }
> void Dispose() { delete this; }
> HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize, void
> *pExArg = 0)
> {
> m_pAlloc = pAlloc;
> m_dwSize = m_pAlloc->GetBlockSize() ;
> m_pData = new BYTE[m_dwSize];
> };
> CDataBlock() : m_lRefCount(0)
> {
> }
> ~CDataBlock()
> {
> delete m_pData;
> m_pData = 0;
> m_pAlloc = 0;
> }
> };
> };// Unmanaged
>
> Nadav
> http://www.ddevel.com


Nov 17 '05 #8
Hi Nadav,

The 2 preferred mechanisms are:
1) In general use C++ with its IJW mechanism to write a translation/warpping
layer, or to write a thick implementation for a managed API that eventually
calls down to the ative API.
2) In case the native API a) has a very simple interface (mostly built in
types, not structures of pointers to variable length lists of structure or
some ilk) and b) is stable (not under active development) and c) is a C API
or COM API and not a C++ API and d) you are writing more than a thin
wrapper, alternatively use C#/VB with DLLImport statements to write the
managed API.

In general the bulk of the unmanaged code will stay compiled native although
there are probably going to several cases where a majority does get compiled
to IL.

Ronald

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:7F******** *************** ***********@mic rosoft.com...
Hi Ronald, Thanks for your detailed responce, I would just like to clarify
a thing: in youre responce you ve saied: "Internally the guidelines are to
use C++ and not COM interop..." by saying 'the guidelines are to use C++'
do you reffer to mixed mode C++? what is the guidlines for exposing an
unmanaged code to a managed code?

Nadav
http://www.ddevel.com
"Ronald Laeremans [MSFT]" wrote:
inline.

"Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
news:A8******** *************** ***********@mic rosoft.com...
> Hi Ronald, Thanks for your response, Still, I have some open issues:
> 1. Is it possible to define an unmanaged class ( not static ) and
> expose
> it using CLI in a way that it would be able to be accessed from managed
> and unmanaged code? ( i didn't find any in the current VS version and
> in
> VS2005.Beta ), My alternative is to use COM which I would really like
> to
> avoid...

No, it isn't in a practical sense of the word. I am not sure why you want
to
avoid using a managed class though. That is a far superior mechanism to
COM
in any way I could think of. AT least in the aspects of performance,
maintainability and ease of development.
> 2. I Did several performance tests with VS2005.Beta, unmanaged C++ if
> far
> more efficient then C#, one of the tests I have done involved mixed
> mode
> C++ ( using VS2005 ), I have wrapped my (efficient) unmanaged project
> with
> a managed wrapper, running this project result performance of about 90%
> of
> the original unmanaged project, note that the managed code used merely
> as
> an entry point to execute the unmanaged code ( e.g.
> MyObj->RunUnmanaged () ), why does performance is lost? it seems that
> loading the CLR it-self causes a performance loss...

If your API is very chatty (e.g. method executions only take a few to a
few
hundreds of instructions) then the interop overhead could explain this.
If
you are measuring only a very small timeframe and your measurement
includes
startup (rather that steady state performance) that could indeed be an
explanation. If it is neither, I fear that only using a decent profiler
will
get you closer to understanding where you are losing the 10% in
performance.
> 2.1. Some words of the test application: it is a winsock app that use
> IOCompletion port for async IO.
>
> P.S.
> How do the guys in Microsoft treat this kind of problems? What language
> is
> used for performance critical modules ( I guess it is unmanaged C++ )
> that
> should interact with managed assemblies? What would be the best way of
> implementing a performance critical module ( CLI, COM, ... ) that
> should
> interact with managed code ?

Internally the guidelines are to use C++ and not COM interop. COM interop
is
used internally only to intercat with existing COM objects. We never
create
new COM interfaces just to be able to use COM interop as the interaction
point.

>
> Nadav
> http://www.ddevel.com
>
> "Ronald Laeremans [MSFT]" wrote:
>
>> Create your methods as static members of a __value or __gc class. Then
>> you
>> will be able to access them for the managed side.
>>
>> Ronald Laeremans
>> Visual C++ team
>>
>> "Nadav" <Na***@discussi ons.microsoft.c om> wrote in message
>> news:A0******** *************** ***********@mic rosoft.com...
>> > Hi,
>> >
>> > I am writing a performence critical application, this require me to
>> > stick
>> > to unmanaged C++ as performance is much better using unmanaged C++ (
>> > about
>> > 33% better ), Still, I am trying to avoid the usage of old style
>> > COM,
>> > my
>> > alternative is to expose my unmanaged interface through the CLI, to
>> > achieve that I have created a mixed mode DLL in which my unmanaged
>> > class
>> > are defined.
>> > When referencing the DLL just described in another mixed mode EXE I
>> > can
>> > see the unmanaged methods through the 'Object browser' BUT, I can't
>> > reference them through code, the namespace of the DLL is not
>> > recognised....
>> > When using a managed C# EXE to reference the unmanaged CLI assembly
>> > the
>> > namespace is identified BUT the contained objects are not...
>> > Is it possible to expose unmanaged interface through the CLI??? is
>> > it
>> > possible to reference this type of interface through another mixed
>> > mode
>> > assembly? will VS2005 support this kind of functionality?
>> >
>> > Bellow is a fragmet of the mixed mode ( unmanaged ) assembly I have
>> > created:
>> > namespace Unmanaged
>> > {
>> > __nogc interface IBlockAllocator ;
>> > __nogc interface IDataBlock
>> > {
>> > virtual HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD
>> > dwSize,
>> > void *pExArg) = 0;
>> > virtual IBlockAllocator *Allocator()= 0;
>> > virtual BYTE *Pointer()= 0;
>> > virtual const DWORD Size()= 0;
>> > virtual LONG AddRef() =0;
>> > virtual LONG Release()= 0;
>> > virtual void Dispose()= 0;
>> > };
>> >
>> > __nogc class CDataBlock : public IDataBlock
>> > {
>> > protected:
>> > DWORD m_dwSize;
>> > LONG m_lRefCount;
>> > BYTE *m_pData;
>> > IBlockAllocator *m_pAlloc;
>> > public:
>> > IBlockAllocator *Allocator() { return m_pAlloc;}
>> > BYTE *Pointer() { return m_pData;}
>> > const DWORD Size() { return m_dwSize;}
>> > LONG AddRef() { return InterlockedIncr ement(&m_lRefCo unt); }
>> > LONG Release()
>> > {
>> > if(0 != InterlockedDecr ement(&m_lRefCo unt))
>> > return m_lRefCount;
>> > m_pAlloc->ReturnToCache( this);
>> > return 0;
>> > }
>> > void Dispose() { delete this; }
>> > HRESULT Initialize(IBlo ckAllocator *pAlloc, const DWORD dwSize,
>> > void
>> > *pExArg = 0)
>> > {
>> > m_pAlloc = pAlloc;
>> > m_dwSize = m_pAlloc->GetBlockSize() ;
>> > m_pData = new BYTE[m_dwSize];
>> > };
>> > CDataBlock() : m_lRefCount(0)
>> > {
>> > }
>> > ~CDataBlock()
>> > {
>> > delete m_pData;
>> > m_pData = 0;
>> > m_pAlloc = 0;
>> > }
>> > };
>> > };// Unmanaged
>> >
>> > Nadav
>> > http://www.ddevel.com
>>
>>
>>


Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2199
by: Mike Kamzyuk | last post by:
Hello all. Basically, I need to call a mixed-mode dll's function (which uses managed code) from a native or mixed-mode dll function (which does not use managed code). I'm wondering if this could be accomplished and how. Here's the problem. We have a third party app (TPA) capable of loading native and mixed-mode dlls somehow (we don't know how). It loads our native dll (OND) and allows us to use our code inside the app (that is, we...
3
1795
by: Nadav | last post by:
Hi, I am writing a mixed mode application, I have a mixed mode Assembly manipulating a managed byte array, to access this array in unmanaged code I '__pin' the array, As I understand, pining an object guarantee that it will not be collected by the GC ( by increasing it's refcount or so ), Taking that in mind, looking at the code generated by the compiler I can't see anything taking care of the GC refcount... following is the pinned variable...
9
2590
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and explain it. I have some questions about the instructions for creating a mixed mode DLL in the MSDN topic "Converting Managed Extensions for C++ Projects from Pure Intermediate Language to Mixed Mode" in the "Managed Extensions for C++ Reference"....
8
3506
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
1
1326
by: rudi | last post by:
Hi everybody, I have a problem with a mixed mode application. It consists of an unmanaged C++ dll, a "mixed mode" dll and various VB.NET dlls using the mixed mode dll to talk to the unmanaged dll. When running on a development machine, everything works just fine. But when deploying on a production machine, there is an error: the mixed mode dll or one of its dependencies can not be found.
2
1646
by: Doug Belkofer | last post by:
We have created a fairly complex mixed-mode DLL that we want to use from VB.NET. The mixed-mode DLL is written in C++, and does use the standard C runtime libraries. An unusual thing is happening in that when we look at this DLL from the Object Browser in Visual Studio, it seems to be exporting several items related to the standard C runtime libraries. One example is that there is a namespace called "std" in the Object Browser, and in that...
0
956
by: Doug Belkofer | last post by:
We have created a fairly complex mixed-mode DLL that we want to use from VB.NET. The mixed-mode DLL is written in C++, and does use the standard C runtime libraries. An unusual thing is happening in that when we look at this DLL from the Object Browser in Visual Studio, it seems to be exporting several items related to the standard C runtime libraries. One example is that there is a namespace called "std" in the Object Browser, and in that...
3
2781
by: Mali Guven | last post by:
Hello, I have a native DLL (written in C) which is supposed to call a managed DLL (was written in C#, and an entry point was injected modifying the ildasm'd code). The exectuable calls the native DLL but the native DLL fails to load the managed DLL. The paper that addresses the 'mixed DLL problem' below does not offer any understandable workaround....
8
2315
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
0
8860
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9381
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9234
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9151
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9086
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.