Configure Memory Allocation for AUTOSAR Adaptive Service Data
To send service event data, the AUTOSAR Adaptive Platform supports these methods:
By reference — The send function uses memory in the application address space. After the send returns, the application can modify the event data.
By
ara::com
allocated memory — The application requestsara::com
middleware to allocate memory for the data. This method avoids data copies byara::com
middleware and can be more efficient for frequent sends or large amounts of data. But the application loses access to the memory after the send returns.
To configure memory allocation for event sends, open the Code Mappings editor. Select
the Outports tab and examine each outport. When you select an
outport, the editor displays the code attribute AllocateMemory
. To
send event data by ara::com
allocated memory, select the value
true
. To send event data by reference, select
false
.
If you set AllocateMemory
to true
, in the
generated C++ model code, the corresponding event send uses an
ara::com
allocated buffer.
void autosar_LaneGuidanceModelClass::step() { ... ara::com::SampleAllocateePtr<company::chassis::provided::skeleton::events:: rightHazardIndicator::SampleType> *rightHazardIndicatorAllocateePtrRawPtr; std::shared_ptr< ara::com::SampleAllocateePtr<company::chassis::provided:: skeleton::events::rightHazardIndicator::SampleType> > rightHazardIndicatorAllocateePtrSharedPtr; ... rightHazardIndicatorAllocateePtrSharedPtr = std::make_shared< ara::com:: SampleAllocateePtr<company::chassis::provided::skeleton::events:: rightHazardIndicator::SampleType> > (ProvidedPort->rightHazardIndicator.Allocate()); rightHazardIndicatorAllocateePtrRawPtr = rightHazardIndicatorAllocateePtrSharedPtr.get(); // Send: '<S8>/Message Send' *rightHazardIndicatorAllocateePtrRawPtr->get() = rtb_Merge1; // Send event ProvidedPort->rightHazardIndicator.Send(std::move (*rightHazardIndicatorAllocateePtrRawPtr)); }