简体   繁体   English

Tibco EMS C API tibemsMsg_GetCorrelationID() 如何为相关 ID 释放内存?

[英]Tibco EMS C API tibemsMsg_GetCorrelationID() how the memory gets freed for the correlation id?

In TIBCO EMS C APIs there are some API whose usage documentation is not very clear.在 TIBCO EMS C API 中,有一些 API 的使用文档不是很清楚。

for example, the documentation for the below APIsays例如,以下 API 的文档说

tibems_status tibemsMsg_GetCorrelationID( tibemsMsg message, const char** value ); tibems_status tibemsMsg_GetCorrelationID( tibemsMsg 消息, const char** 值);

Parameters Description参数说明

message: Get the type header of this message. message:获取此消息的类型头。
value : Store the type. value : 存储类型。

What Does the Store mean here?商店在这里是什么意思? Is new memory allocated for value?是否为价值分配了新内存? How does the memory get freed for value?如何释放内存以获取价值?

By calling tibemsMsg_Destroy() the message is destroyed, but I could still print the correllationID.通过调用 tibemsMsg_Destroy() 消息被销毁,但我仍然可以打印 correllationID。

If the message is destroyed then how correlationID is still available?如果消息被破坏,那么correlationID 仍然可用?

For best performance, this call returns you the address of the correlation ID within that message.为获得最佳性能,此调用将返回该消息中相关 ID 的地址。

You can copy it if you need it, but should not use it after destroying that message.如果需要,您可以复制它,但不应在销毁该消息后使用它。 It might still be visible after destroy BUT it is now part of the freed memory and could be overwritten with other things anytime.销毁后它可能仍然可见,但它现在是已释放内存的一部分,并且可以随时被其他内容覆盖。

A typical use case might be this to copy the content into an std::string.一个典型的用例可能是将内容复制到 std::string 中。

std::string correlationID;
const char* id = NULL;
status = tibemsMsg_GetCorrelationID( jmsMsg, &id );
if( status==TIBEMS_OK && id!=NULL ) {
  correlationID = id; // COPY the null-terminated string pointed to by 'id'
}
// later: tibemsMsg_Destroy()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM