Memory management inside the SDK

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
dy_100000
Full Member
Full Member
Posts: 9
Joined: 11 May 2012, 09:53

Memory management inside the SDK

Post by dy_100000 »

Hi, support team:

I'm implemeting a high availability system by using UA C++ SDK, and the memory management is one of the important issue I need to think about. So I’d like to confirm that is there a memory pool implementation inside the core of SDK, which allows to allocate/dealloce the UA objects(UaString, UaArray) rapidly and safely.

Thanks

Regards

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re:Memory management inside the SDK

Post by Support Team »

Hi,

The C++ SDK is not using memory pools since regular new/delete is used. With the ANSI C SDK it would be possible to use memory pools in the platform layer instead of malloc / free to the operating system / C runtime.

But I assume you are not talking about memory pools but about memory management.

All classes in the C++ SDK like UaString and the UA stack array wrapper classes are doing their own memory management. The take care about allocating and initializing memory and freeing memory of internal ANSI C stack structures. The only thing you need to care about is the management of C++ objects created with new in your code.

Best Regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team

dy_100000
Full Member
Full Member
Posts: 9
Joined: 11 May 2012, 09:53

Re:Memory management inside the SDK

Post by dy_100000 »

Hi,

Thanks lot for your response. The word “memory management” I used may be not detailed enough, because it refers to several issues(pointer counter, initialization/free and allocation/deallocation, etc). Sorry about it. :-)

In fact, the issue that interests me the most is memory allocation/deallocation. Because the system I’m implementing is based on event-driven mechanism, and the size of each event is usually small. To prevent memory fragment and to allocate faster, I decide to use memory pool.

The problem is that some of my event structure contains UA objects(UaNodeId, UaDataValue, UaString, etc), but the allocation/deallocation of those UA Objects can not be managed by myselve. So in that case, I’m asking if there is a memory pool inside the C++ SDK.

I guess the reason that the SDK does not adopt a memory pool is that it runs on modern PC-based system. Unlike embedded system, the PC-based system has enough resource, and a memory pool does not make a lot of optimization. Is that right?

Regards

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re:Memory management inside the SDK

Post by Support Team »

Hi,

The C++ SDK was designed for PC based systems or high end embedded systems. Introducing memory pools here would require overwriting the standard C++ new/delete.

If you want to have better control for memory management and if you want to be able to use memory pools you should have a look at the ANSI C based server SDK.
The ANSI C SDK was designed for smaller embedded devices and all allocations are done through the platform layer functions OpcUa_Malloc / OpcUa_Free. This makes it possible to apply memory pools to this SDK.

Best Regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team

Post Reply