CMSIS-DSP  
CMSIS DSP Software Library
 
Loading...
Searching...
No Matches
DSP++ Vector and Memory Allocator Example
Description:
Demonstrates fused vector expressions and custom memory allocators using the CMSIS-DSP C++ template library (DSP++). Two tests evaluate the same expression with statically and dynamically sized vectors of 64 floating-point elements.
Algorithm:
The input vectors are initialized with a[i] = b[i] = c[i] = i. The expression d = a + b * c computes d[i] = i + i * i for indices 0 through 63. Addition and multiplication are fused into a single vectorized loop, avoiding an intermediate array for the product. On Helium, the loop uses predication. Both tests print the resulting vector.
Memory Allocators:
  • test1 uses statically sized vectors and the allocator selected by TMP_ALLOC in Dsppp/Dsppp.cproject.yml. The default pool_allocator supplies four 256-byte buffers, one for each vector of 64 floats.
  • test2 uses dynamically sized vectors with an explicit arena_allocator. A 1024-byte arena is allocated with 64-byte alignment. Each allocation rounds the arena offset up to a multiple of ALIGN (64 by default), assuming the arena base is already aligned. Individual deallocations do nothing; resetting the arena reclaims all its allocations. The test prints the consumed bytes before resetting and freeing the arena.
  • Temporary vectors still use TMP_ALLOC. When their allocator differs from the destination allocator, their data is copied instead of moved.
Allocation Statistics:
To determine memory pool sizes, change TMP_ALLOC to stat_allocator and enable STAT_ALLOCATOR in Dsppp/Dsppp.cproject.yml. After test1, the example prints peak allocation counts and checks for outstanding allocations.
Variables Description:
  • a, b, c are the input vectors.
  • d is the result vector.
  • NB is the number of elements in each vector (64).
  • ARENA_SIZE is the arena capacity in bytes (1024).
CMSIS-DSP C++ Library Features Used:
  • Vector templates with static and dynamic dimensions.
  • Fused element-wise addition and multiplication.
  • MemoryPool and custom allocator templates.

See also Memory allocation for the custom allocator interface.

Refer dsppp_example/Dsppp/main.cpp