Re: how to pass lots of data from unmaged to manage code using CCW
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Tue, 1 Apr 2008 00:48:12 +0200
Well, from what I understood, I can say that you don't need to make it that complicated and slow.
The first option is to get rid of the .NET remoting part, and use DCOM as protocol, to do this you have to:
- Derive a class from System.EnterpriseServices.ServicedComponent and register the class (using regsvcs.exe) to run as a COM+ server type application (out-proc).
- Export a proxy, for this application, using COM+ admin (run dcomcnfg.exe).
- Install the proxy (an MSI file) on the client machine(s).
- COM clients and .NET clients can now call the COM+ server application on the remote server.
In order to reduce the marshaling overhead you'll have to specify your data structure at the server (C#) like this:
[Guid("your own private guid here")]
[ComVisible(true)]
public struct strValue
{
public int count;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string chName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string chAddress;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string price;
public int enKind;
}
Adapt the SizeConst values to suit your needs, note that I assume your char fields have a fixed length.
The above declarations will export the structure in the tlb file with the string fields declared as:
unsigned char chName[64];
...
};
At the server (C++) you need to:
- import the typelib created when running regsvcs.exe above using VC++ "import" directive.
#import "your_server.tlb" no_namespace
- To get at the record description (the above structure) you'll have to call GetRecordInfoFromGuids , and pass the recordInfo in the call to SafeArrayCreateEx, something like this....
strValue *pstrValue = NULL;
IRecordInfo *precordInfo = NULL;
HRESULT hr = GetRecordInfoFromGuids( __uuidof(__SomeClass),
1, 0, 0, __uuidof(strValue),
&pLoadRecordInfo );
// set the array bounds...
// and create the sa
LPSAFEARRAY psastrValue = SafeArrayCreateEx(VT_RECORD, 1, rgsabound, precordInfo );
...
hr = SafeArrayAccessData(psastrValue , reinterpret_cast<PVOID*>(&pstrValue ));
// fill the array with data.. using
// and detach when done
SafeArrayUnaccessData(...)
call the server passing the array as argument.
Note that your requirements of 10000 structures per second cannot be guraranteed, you'll have to measure, but with a structure size 200 bytes and a fast reliable and not congested network (>= 100Mbps), it should be possible to pass 10000 * 200 byte structures over DCOM .
The second option is to get rid of both COM and .NET remoting, and go for a socket based client/server solution, this is the fastest solution, but you loose quite a bit offered by the COM+ infrastructure, you need to write more code, and you need to marshal the structure yourself, but as the structure is quite simple, this shouldn't be an big issue.
Willy.
"lightdoll" <djyang32@xxxxxxxxx> wrote in message news:22569E4D-E9B8-4D6C-950D-E90C63DFA791@xxxxxxxxxxxxxxxx
hello willy..
thank you for your reply.
(A) C++ <-- COM --> (B) C# <--- .NET remoting ---> (C) C#
= > yes, i want to make my program like above.
= > i want to exchange data from win32, and C++.
How did you measure?
=> i wrote a time in cosole at remote server after Server received data from
client.
What (results) did you measure?
=>time...
What did you expect?
What are you requirements?
What data types are you passing?
=> i made a structure like below
=> typedef structure strValue
{
int Count;
char *chName;
char *chAddress;
char *price;
enum enKind;
}
=> i want to send the struture 10000 Numbers for 100ms from client to server
COM interop:=> before i made out-of-process with singleton by atl.
Is this an in-proc , or out-proc server scenario?
=> but today i have made new one with in-process using C#.
..NET remoting:=> different machine and local network.
What's the "distance" between B and C (same machine , local network,
WAN, ...)?
What's the protocol used?
=> tcp/ip
What kind of formatter do you use?
=> binary.
can i ask you soemthing?
i have made in-process using C# today.
i passed variant between c++ and C#.
so i have to prepare variant type in c++.
can i pass structure from c++ to C#.
because if i can send structure from c++ to C#.
that is better than send variant from c++ to C#
thank you very much ...
"Willy Denoyette [MVP]" wrote:
From what I understand, you have the following scenario:
(A) C++ <-- COM --> (B) C# <--- .NET remoting ---> (C) C#
and you say it is slow when passing a lot of data, right?
Well, I can't help you if you don't answer all of the questions asked
previously, notably the following question are key:
How did you measure?
What (results) did you measure?
What did you expect?
What are you requirements?
What data types are you passing?
COM interop:
Is this an in-proc , or out-proc server scenario?
What types do you pass from A to C?
What's the size of the data?
..NET remoting:
What's the "distance" between B and C (same machine , local network,
WAN, ...)?
What's the protocol used?
What kind of formatter do you use?
Willy.
Sorry, but I can't help you if you don't answer the questions asked
previously.
"lightdoll" <djyang32@xxxxxxxxx> wrote in message
news:82134C33-3060-4E40-B2AB-BFB0CC3BB555@xxxxxxxxxxxxxxxx
> hello willy..
>
> i am using c++ for client,
>
> ok i wrote how to make my software..
>
> i want to use net remote for server.
>
> so i alredy made a server using Net Remote.
>
> i want to send lots of data from client that is C++.
>
> so i need to make Net Client of Remote using C#.
>
> a client of c++ will send the Net Client have Net Remote.
>
> so i need to convert net client to com for using C++.
>
> do you have any idea to send lots of data from client to server using > Net
> Remote
>
> any function.
>
> "Willy Denoyette [MVP]" wrote:
>
>> "lightdoll" <djyang32@xxxxxxxxx> wrote in message
>> news:1F7FAA16-E02F-4B86-811C-DFA709580808@xxxxxxxxxxxxxxxx
>> > hello everyone
>> >
>> > i want to send lots of data from unmanaged to mange code using CCW.
>> >
>> Please define "unmanaged" code! What language is the client written >> in?
>> Is
>> this a late bound or early bound scenario?
>> What do you call a lot of data?
>> Why do you use COM to transfer "lots of data"? COM was not designed to >> be
>> used as a data transfer protocol!
>>
>>
>> > i have made this kind of code with variant, but it was slow..
>> >
>>
>> What do you call slow, how did you measure, on what OS and HW >> platform?
>> what were your expectations?
>>
>> > for example
>> >
>> > because i have to make variant type like safearray, before send >> > variant
>> > to
>> > manage code.
>> >
>>
>> What makes you think you need a variant type?
>>
>> > so there is loop to make variant type..
>> >
>>
>> Hmm..., posting some code might help us to understand the issue.
>>
>> > how can i solve this kind of problem.
>> >
>> > please..help me..
>> >
>> First we need you to answer the above questions.
>>
>> Willy.
>>
>>
>>
>>
.
- Prev by Date: Re: a state machine design question
- Next by Date: Re: command line program doesn't run!
- Previous by thread: milk feeding
- Next by thread: Re: command line program doesn't run!
- Index(es):
Relevant Pages
|