question

Upvotes
Accepted
22 3 3 7

For object com.refinitiv.ema.access.Msg how do I make a deep copy of it?

I want to efficiently take a message from the inbound queue manged by the SDK and add it to a local queue - making this the only function of that thread. A simple assignment is only copying a pointer, not the data itself. Using this pointer later leads to all kinds of data corruption issues as it has been deallocated in the SDK.

ema-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
78.8k 250 52 74

@Patrick Sweeney

The message object passed as a parameter to the callback is owned by SDK. The object and all objects inside that message object must not be used outside the callback.

You can extract the required data, such BID and ASK values from the message and then add it to a local queue, as mentioned by my colleague.

Otherwise, since EMA 3.3.1 (RTSDK C++/C Release 1.3.1.L1), EMA is able to clone and copy messages in order to decode payload outside of message callbacks.

EMA C++ uses a copy constructor.

void AppClient::onRefreshMsg( const RefreshMsg& refreshMsg, const OmmConsumerEvent& ) 
{
    RefreshMsg* msgPtr = new RefreshMsg(refreshMsg);
...
}

EMA Java uses the EMAFactory.

    public void onRefreshMsg(RefreshMsg refreshMsg, OmmConsumerEvent event)
    {        
        RefreshMsg msg = EmaFactory.createRefreshMsg(refreshMsg);
        ...
    }

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
22k 58 14 21

Hi @Patrick Sweeney,

As you have discovered - OMM messages are owned and reclaimed by the SDK. In my experience, the best means to handle the high message rates, is to quickly decode the payload in the receive thread and handover the decoded object to other thread for further processing. A quick extraction of data in the event callback thread, does not create any throughput bottlenecks - atleast not any more then a deep copy of the object would.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Do I have this correct?

msg is a reference to data managed by the SDK.

msg.payload() returns a reference to data managed by the SDK.

msg.payload().fieldlist() returns a FieldList object.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.