Avoid code generation string.h or memcpy for typecast()

14 vues (au cours des 30 derniers jours)
Roman Foell
Roman Foell le 6 Nov 2022
Hi,
I want to generate C code with Matlab Coder.
I already set in the Advanced Setting: Use memcpy for vector assignment: No
and
Use memset to initialize floats and doubles to 0.0 : No
But for Matlab Code:
typecast(x,'uint32')
or
typecast(x,'single')
it is still using: (void) memcpy
Are there more settings to avoid using string.h and memcpy in specific? Thanks.

Réponses (1)

Shivam Malviya
Shivam Malviya le 11 Nov 2022
Modifié(e) : Shivam Malviya le 11 Nov 2022
Hi Roman,
It is my understanding that you are generating C code from MATLAB code that contains a typecast function.
The generated C code uses string.h and memcpy function, which you want to avoid.
Also, setting the options to the following value did not help;
  1. “Use memcpy for vector assignment”: No
  2. “Use memset to initialize floats and doubles to 0.0: No
As a workaround, the Code Replacement Library (CRL) can be used.
Please follow the workflow mentioned below to achieve the same.
Creating Code Replacement Library for "memcpy"
  1. Download the attached scripts "crl_table_memcpy.m" and "rtwTargetInfo.m" and save them in the current working directory or in the folder that is in MATLAB Path.
  2. To use your code replacement library, refresh your current MATLAB session with the command:
>> sl_refresh_customizations
3. Verify the code replacement library by executing the command
>> crviewer('CRL for memory function replacement')
Code generation
  1. In Generate Code stage of code generation using MATLAB Coder App, open more settings, and set the options' value as below;
a. “Code replacements: Yes
b. “Code replacement library”: CRL for memory function replacement
2. Generate the code
After using Code Replacement Library, it can be observe that “memcpy” is replaced with “my_memcpy”;
  • Before
  • After
Below are the links to detailed documentation of the steps mentioned above;
Hope this helps!
Regards,
Shivam Malviya

Catégories

En savoir plus sur MATLAB Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by