Memory allocated for and by the trusted application at run time is also allocated from a pool of total heap memory for all trusted applications. Here too, decreasing the memory needed to be allocated will increase the possibility of running more trusted applications. It should be noted that this memory includes memory explicitly allocated by the trusted application as well as memory allocated by the System for use with the trusted application, such as stack memory, meta data and other memory needed by the System to support running the trusted application.
Trusted applications should not require a heap larger than 64K bytes. If the trusted application uses the UI interface then it may need a heap as large as 90K bytes. Decreasing the trusted application code memory footprint will increase the possibility of loading the trusted application when there are other trusted applications already loaded; further, a smaller trusted application will leave more room for other trusted applications.
The SDK in Intel® DAL provides memory profiling tools (built into the firmware emulators – see Determining Actual Memory Requirements for a Trusted Application) to measure the trusted application heap usage. Use the tools to run the entire end-to-end flow of the trusted application (causing the maximum memory usage) to determine the heap usage. Because of the potential of heap fragmentation, it is recommended to add 40% to the estimated trusted application heap usage and use that value as a manifest parameter. You can reduce the impact of fragmentation by allocating larger needed chunks of memory first. Let the garbage collector handle the memory that you are not using. Do not save anything you do not need to hang on to.
Tip:In the Host - Trusted Application Communication flow, the buffer allocation for both Send and Receive operations is taken from the heap of the Trusted Application. In order to minimize the heap size needed, it is recommended not to use buffer sizes that are larger than a few kilobytes.