I am using FreeRTOS with an NXP RW610 series board. I created two tasks, first task is responsible to initialize the network module. The second task is responsible for receiving the UDP packets from the Wi-Fi network. We are using an audio library which is responsible for processing the UDP packets.
While allocating memory for the packet, the code is getting stuck at the “new operator”.
below is the debugger call stack:
WiFi-Link.elf
Thread
#1
57005 (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)
_exit() at 0x8086f40
abort() at 0x8084814
operator new() at 0x80a7efc
__gnu_cxx::new_allocator::allocate() at new_allocator.h:121 0x804bf90
std::allocator_traits<std::allocator >::allocate() at alloc_traits.h:460 0x804b1a0
std::_Vector_base<unsigned char, std::allocator >::_M_allocate() at stl_vector.h:346 0x804a3d4
std::vector<unsigned char, std::allocator >::_M_allocate_and_copy<__gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator > > >() at stl_vector.h:1,511 0x8055124
std::vector<unsigned char, std::allocator >::operator=() at vector.tcc:226 0x8053abc
AudioDistributorPacket::operator=() at AudioDistributorPacket.h:16 0x805cd7c
FecGrid::Set() at FecGrid.h:93 0x805cec2
Kindly help me to resolve this issue.
regards
Nagesha
Hi [CHING-HSIN, LEE],
Thank you for your quick response.
Kindly let us know how to redefine new() and delete() APIs in a dedicated C file.
In fact, I was going through the thread link and tried to redefine the allocation in a new file called utility.c. But I am getting below build error for “operator new”.
utility.c:1:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘
attribute
’ before ‘new’
1 | void * operator new( size_t size )
Hi RAc,
Thank you for your response. I change the file extension from utility.c to utility.cpp. Now new()/delete() operators are working fine as expected.
Regards
Nagesha
Great it’s working! Now pay attention to which version of
malloc()
the
new
operator is using, so that you don’t get surprises in the future.
FreeRTOS allows you to choose among several
malloc()
versions. There exist a version that don’t implement the
free()
functionality. Another behaves exactly as the
malloc()
C standard. Other allows you to write your own object’s pool.
Besides that, in memory constrained systems memory fragmentation can lead to memory allocation problems (even if you think you have plenty of RAM available). Whenever possible, allocate memory statically (for your tasks and objects).