Home Help Center

Out-Parameters

soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
Hey,guy:
i want use sequence<byte> ByteSeq as Out-Parameters, that also back big data,so i want use array mapping for achieve zero-copy passing of sequences.

How deal with it ?
TKS.

Comments

  • dwaynedwayne St. John's, NewfoundlandMember Dwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications Engine
    Hi,

    In order to get zero-copy for return values you need to use AMI in your client and AMD in your server. Your slice might look something like
    #include<Ice/BuiltinSequences.ice>
    
    module Test
    {
    
    interface Iface
    {
        ["ami", "amd"] void getBytes(out ["cpp:array"] Ice::ByteSeq b); 
    };
    
    };
    

    See Chapter 33 of the manual for more info on AMI/AMD.

    Dwayne
  • soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
    fast copy

    yeah,iGet it,and other trouble is i want copy data like this:

    ByteSeq byteSeq(ByteSeqSize);
    pair<const Ice::Byte*, const Ice::Byte*> byteArr;
    byteArr.first = &byteSeq[0];
    byteArr.second = byteArr.first + byteSeq.size();


    how ?

    :confused:
  • dwaynedwayne St. John's, NewfoundlandMember Dwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications Engine
    Sorry, but I don't understand your question. What is it that you want to do and what is the problem you are having doing it?
  • soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
    I'm so sorry about it.

    in my project,i use Out-Parameters to get the result,but sometimes,it's huge big,so i try to use sequence<byte> out the result, i define .ice like :
    sequence<byte> ByteSeq;
    interface Hello
    {
    void sayHello(int delay,out ByteSeq byteSeq);
    }


    so just like client send a num,and server out back a big data,
    now,i have no idea about out back ,it's so big,i want server copy data as soon as he can.
    In Ice-3.2.1-VC71\demo\Ice\throughput, i found Array Mapping for Sequences,so i think maybe Array can help me to achieve zero-copy passing of sequences.

    can i do it ? tks.
  • soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
    hey, dwayne

    I alos read AMI/AMD.should i do that(above) without use it?
  • dwaynedwayne St. John's, NewfoundlandMember Dwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications Engine
    As I stated in my first response, if you want to have zero-copy for an out paramater then you need to use AMI/AMD. So if we use the slice that I used previously, on the server side your servant would implement the getBytes_async AMD method. Something like:
    void
    IfaceI::getBytes_async(const ::Test::AMD_Iface_getBytesPtr& cb, const ::Ice::Current& current)
    {
        pair<const Ice::Byte*, const Ice::Byte*> outPair;
        // Set pair first/second to point at your data 
        cb.ice_response(outPair);
    }
    

    On the client side you would use the AMI method to call getBytes. Something like:
    class AMI_Iface_getBytesI : public AMI_Iface_getBytes
    {
    public:
    
        void ice_response(const pair<const ::Ice::Byte*, const ::Ice::Byte*>& bytes)
        {
            // Do what you need to do with data
        }
        ...
    };
    
    typedef IceUtil::Handle<AMI_Iface_getBytesI> AMI_Iface_getBytesIPtr;
    
    main()
    {
        ...
        IfacePrx prx = ... // obtain proxy
    
        AMI_Iface_getBytesIPtr cb = new AMI_Iface_getBytesI();
        prx->getBytes_async(cb);
        ...
    }
    

    I hope this makes it clearer what you need to do to reduce the amount of copying for out parameters to a minimal. The same would apply for using return values rather than an out.

    Dwayne
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    If you're returning a stack-allocated vector<Ice::Byte> from your servant, then with many C++ compilers, you can take advantage of Named Return Value Optimization (NRVO).

    In this case, no need to use AMD to implement your operation: this compiler optimization avoids the vector copying.

    Cheers,
    Bernard
  • soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
    Thanks a lot, for your input, these are great answers.
  • soff.dongsoff.dong Member qiao dongOrganization: accuradProject: v6's net project ✭✭
    Thanks a lot, for your input, these are great answers.
Sign In or Register to comment.