Using shared pointers with MATLAB Coder

Hello guys,
My question is actually pretty straightforward. How do I use shared_ptr with generated C++ code from MATLAB? For example, I can pass a shared_ptr instead of a regular ptr to MATLAB-generated functions? If yes, how?
My first thinking is that I would have to change it manually in the function declaration, but I believe I could be so susceptible to errors this way.

답변 (1개)

SACHIN KHANDELWAL
SACHIN KHANDELWAL 2025년 1월 23일

0 개 추천

For smart pointers, while MATLAB Coder doesn't generate shared or unique pointers, it can wrap dynamic memory allocation in a more modern interface that guards calls to "new" with a wrapper called coder::array. This should be safer than emxArrays. You can do this by setting DynamicMemoryAllocationInterface to 'C++' which should be the default when generating C++ code.

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

질문:

2021년 4월 12일

답변:

2025년 1월 23일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by