Skip to content

Latest commit

 

History

History
95 lines (78 loc) · 5.19 KB

reduce_memory.rst

File metadata and controls

95 lines (78 loc) · 5.19 KB

Reduce memory usage

A great number of modern systems have tight constraints on available memory, making the reduction of memory usage to a minimum critical. Reducing memory consumption of a Fast DDS application can be achieved through various approaches, mainly through architectural restructuring of the application, but also by limiting the resources the middleware utilizes, and by avoiding static allocations.

Limiting Resources

The :ref:`resourcelimitsqospolicy` controls the resources that the service can use in order to meet the requirements imposed. It limits the amount of allocated memory per :ref:`dds_layer_publisher_dataWriter` or :ref:`dds_layer_subscriber_dataReader`, as per the following parameters:

All these parameters may be lowered as much as needed to reduce memory consumption, limit the resources to the application's needs. Below is an example of a configuration for the minimum resource limits possible.

Warning

C++
.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //CONF-MEMORY-QOS-PUBSUB
   :end-before: //!--
   :dedent: 8
XML
.. literalinclude:: /../code/XMLTester.xml
   :language: xml
   :start-after: <!-->CONF-MEMORY-QOS-PUBSUB
   :end-before: <!--><-->
   :lines: 2-3,5-
   :append: </profiles>

Set Dynamic Allocation

By default :ref:`memorymanagementpolicy` is set to |PREALLOCATED_WITH_REALLOC_MEMORY_MODE-api|, meaning that the amount of memory required by the configured :ref:`resourcelimitsqospolicy` will be allocated at initialization. If some more memory has to be allocated at run time, it is reallocated.

Using the dynamic settings of the :ref:`rtpsendpointqos` will prevent unnecessary allocations. Lowest footprint is achieved with |DYNAMIC_RESERVE_MEMORY_MODE-api| at the cost of higher allocation counts, in this mode memory is allocated when needed and freed as soon as it stops being used. For higher determinism at a small memory cost the |DYNAMIC_REUSABLE_MEMORY_MODE-api| option is available, this option is similar but once more memory is allocated it is not freed and is reused for future messages.

C++
.. literalinclude:: /../code/DDSCodeTester.cpp
   :language: c++
   :start-after: //CONF-MEMORY-QOS-ENDPOINTS
   :end-before: //!--
   :dedent: 8
XML
.. literalinclude:: /../code/XMLTester.xml
   :language: xml
   :start-after: <!-->CONF-MEMORY-QOS-ENDPOINTS
   :end-before: <!--><-->
   :lines: 2-3,5-
   :append: </profiles>