# Allocate Memory for Scratch Buffers

Memory that is required during the execution process needs to be
allocated through `HAP_malloc/HAP_free` call defined in the SDK.
Currently, HTP core ops do not use any scratch buffers.

Here are the function calls allocate/free memory during execution:

// allocate memory
    // [in] bytes size of memory block in bytes.
    // [out] pptr pointer to the memory block
    // Returns: int AEE_SUCCESS for success and AEE_ENOMEMORY for failure.
    static int HAP_malloc(uint32 _bytes_, void ** _pptr_)
    
    // free memory
    // [in] **pptr** pointer to the memory block
    // Returns: int AEE_EBADCLASS if ptr is NULL AEE_SUCCESS if ptr is not NULL
    static int HAP_free(void *_ptr_)
    Copy to clipboard

`HAP_malloc` and `HAP_free` are simple wrappers around the DSP
malloc and free functions. If a user memory allocation request cannot be
fulfilled with the existing DSP heap, the FastRPC runtime will attempt
to grow the DSP heap by reserving additional memory from the HLOS.

For more information, view documentation on `HAP_alloc` and
`HAP_free` from the SDK doc.

Note

It is strongly discouraged to allocate memory in op
execution. The time to finish the allocation is unbounded and
could impact the inference speed significantly.

Last Published: Jun 04, 2026

[Previous Topic
Scheduling and Allocation](https://docs.qualcomm.com/bundle/publicresource/80-63442-10/topics/scheduling_and_allocation.md) [Next Topic
Tensors and Memory Layout](https://docs.qualcomm.com/bundle/publicresource/80-63442-10/topics/tensors_and_memory_layout.md)