What is zalloc in embedded programming?

I am programming a serial-wifi ESP8266 chip. In his SDK examples, he makes extensive use of a feature called os_zalloc

where I would expect malloc

.

Sometimes, however, it is used os_malloc

. So they don't seem to be the same in function.

Unfortunately, there is no documentation. Can anyone make an educated guess from the following header file?

#ifndef __MEM_H__
#define __MEM_H__

//void *pvPortMalloc( size_t xWantedSize );
//void vPortFree( void *pv );
//void *pvPortZalloc(size_t size);

#define os_malloc   pvPortMalloc
#define os_free     vPortFree
#define os_zalloc   pvPortZalloc

#endif

      

+4


source to share


3 answers


Since it os_zalloc

is a macro and the definition is given in mem.h, it is better to ask what it does pvPortZalloc

.

Given the function names pvPortMalloc

, vPortFree

and pvPortZalloc

it looks like the OS being used is FreeRTOS (or is it a commercially licensed equivalent to OpenRTOS), which is documented - although not specifically pvPortZalloc

, but it would be weird if it weren't for just highlighting and null initializing - it is for example then which means here . These functions are part of the porting layer target for FreeRTOS and are not usually called by the application layer, but my guess is that this is using macros to access the porting layer code for the application user, rather than writing it twice.



In the RTOS core, thread safety requires heap-safe functions that support RTOS, although some standard library implementations include thread-safety threads, which you implement with RTOS mutex calls, which is the best practice since existing libraries and C ++ new

/ delete

can more easy to use.

+6


source


I'd say "allocate memory and fill with zeros"



+4


source


when i used os_zalloc () do i need to use zfree ()? I cannot find zfree in 8266 SDK, only free ()

0


source







All Articles