Documentation

Documentation

Includes

tuya_cloud_types.h

#include "tuya_cloud_types.h"
#include "tuya_cloud_types.h"

Macros

Marco _MEM_POOL_H

#define _MEM_POOL_H


      

Marco SYS_MEM_DEBUG

#define SYS_MEM_DEBUG 0 
/**
 * @brief system memory debug flag
 * 
 */

Marco SHOW_MEM_POOL_DEBUG

#define SHOW_MEM_POOL_DEBUG 1 
/**
 * @brief system memory debug  display flag
 * 
 */

Marco MEM_POOL_MUTLI_THREAD

#define MEM_POOL_MUTLI_THREAD 1
/**
 * @brief support multi thread memory process
 * 
 */

Marco Malloc(x)

#define Malloc(x) __Malloc(x,__FILE__,__LINE__)
/**
 * @brief malloc memory
 * 
 * @param[in] reqSize the required memory size 
 * @return  NULL on failed, others on the address of the memory
 */

Marco Calloc(x)

#define Calloc(x) __Calloc(x, y,__FILE__,__LINE__)
/**
 * @brief malloc consecutive memory, the size is reqCount*reqSize
 * 
 * @param[in] reqCount the required memory count
 * @param[in] reqSize the required memory szie
 * @return NULL on failed, others on the address of the memory
 */

Marco Free(x)

#define Free(x) __Free(x,__FILE__,__LINE__)
/**
 * @brief free memory
 * 
 * @param[in] pReqMem the memory address which got from Malloc or Calloc function
 * @return VOID 
 */

Functions

Func SysMemoryPoolSetup

OPERATE_RET SysMemoryPoolSetup(VOID);
/**
 * @brief setup the memory pool use default memory pool table and partition number
 * 
 * @return OPRT_OK on success, others on failed, please refer to tuya_error_code.h    
 */

Func SysMemPoolSetupUserDef

OPERATE_RET SysMemPoolSetupUserDef(IN CONST MEM_POOL_SETUP_TBL *tbl, IN CONST INT_T cnt);
/**
 * @brief setup the memory pool use user defined memory pool table and partition number
 * 
 * @param[in] tbl the memory pool table
 * @param[in] cnt the partition number
 * @return OPRT_OK on success, others on failed, please refer to tuya_error_code.h     
 */

Func SysMemoryPoolDelete

VOID SysMemoryPoolDelete(VOID);
/**
 * @brief delete memory pool
 * 
 * @return VOID 
 */

Func MemPartitionCreate

OPERATE_RET MemPartitionCreate(IN CONST DWORD_T nblks, IN CONST DWORD_T blksize, OUT MEM_PARTITION **ppMemPartition);
/**
 * @brief create memory partotion
 * 
 * @param[in] nblks the number of memory block in partition
 * @param[in] blksize the size of memory block in partition
 * @param[out] ppMemPartition the memory partition
 * @return OPRT_OK on success, others on failed, please refer to tuya_error_code.h     
 */

Func MemPartitionDelete

OPERATE_RET MemPartitionDelete(IN MEM_PARTITION *pMemPart);
/**
 * @brief delete memory partition
 * 
 * @param[in] pMemPart the memory partition need to delete
 * @return OPRT_OK on success, others on failed, please refer to tuya_error_code.h  
 */

Func MemBlockGet

VOID *MemBlockGet(INOUT MEM_PARTITION *pMemPart, OUT OPERATE_RET *pOprtRet);
/**
 * @brief get a memory block from a partition
 * 
 * @param[in] pMemPart the input memory partition
 * @param[out] pOprtRet the operation return value, OPRT_OK on success, others on failed, please refer to tuya_error_code.h
 * @return the memory block address 
 */

Func MemBlockPut

OPERATE_RET MemBlockPut(INOUT MEM_PARTITION *pMemPart, IN CONST VOID *pblk);
/**
 * @brief release memory block to partition
 * 
 * @param[in] pMemPart the memory partition
 * @param[in] pblk the memory block address need to release
 * @return OPRT_OK on success, others on failed, please refer to tuya_error_code.h 
 */

Func MallocFromSysMemPool

VOID *MallocFromSysMemPool(IN CONST DWORD_T reqSize,OPERATE_RET *pRet);
/**
 * @brief malloc memory from memory pool
 * 
 * @param[in] reqSize the size of memory required
 * @param[in] pRet the operation return value, OPRT_OK on success, others on failed, please refer to tuya_error_code.h
 * @return the address of the memory
 */

Func FreeFromSysMemPool

OPERATE_RET FreeFromSysMemPool(IN PVOID_T pReqMem);
/**
 * @brief free the memory to memory pool
 * 
 * @param[in] pReqMem the memory which got from MallocFromSysMemPool function
 * @return OPRT_OK on success, others on failed, please refer to tuya_error_code.h 
 */

Func ShowSysMemPoolInfo

VOID ShowSysMemPoolInfo(VOID);
/**
 * @brief display the memory pool detail info, only valid when SHOW_MEM_POOL_DEBUG=1
 * 
 * @return VOID 
 */

Func __Malloc

VOID *__Malloc(IN CONST DWORD_T reqSize,IN CONST CHAR_T *file,IN CONST INT_T line);
/**
 * @brief a debug function which can record the file and line infomation when call Malloc
 * 
 * @param[in] reqSize the required memory size
 * @param[in] file the file name where Malloc called
 * @param[in] line the line where Malloc called
 * @return the memory address got from system memory pool
 */

Func __Free

VOID __Free(IN PVOID_T pReqMem,IN CONST CHAR_T *file,IN CONST INT_T line);
/**
 * @brief a debug function which can record the file and line infomation when call Free
 * 
 * @param[in] pReqMem the memory address which need to free
 * @param[in] file the file name where Free called
 * @param[in] line the line where Free called
 * @return VOID 
 */

Func Malloc

VOID *Malloc(IN SIZE_T reqSize);
/**
 * @brief malloc memory
 * 
 * @param[in] reqSize the required memory size 
 * @return  NULL on failed, others on the address of the memory
 */

Func Calloc

VOID *Calloc(IN CONST DWORD_T reqCount, IN SIZE_T reqSize);
/**
 * @brief malloc consecutive memory, the size is reqCount*reqSize
 * 
 * @param[in] reqCount the required memory count
 * @param[in] reqSize the required memory szie
 * @return NULL on failed, others on the address of the memory
 */

Func Free

VOID Free(IN PVOID_T pReqMem);
/**
 * @brief free memory
 * 
 * @param[in] pReqMem the memory address which got from Malloc or Calloc function
 * @return VOID 
 */

Vars

Consts

Types

Typedefs

Typedef MEM_PARTITION;

typedef struct {               // MEMORY CONTROL BLOCK                                         
   VOID  *pMemAddr;          // Pointer to beginning of memory partition    
   VOID  *pMemAddrEnd;       // Pointer to ending of memory partition
   VOID  *pMemFreeList;      // Pointer to list of free memory blocks                        
   DWORD_T memBlkSize;       // Size (in bytes) of each block of memory                      
   DWORD_T memNBlks;         // Total number of blocks in this partition                     
   DWORD_T memNFree;         // Number of memory blocks remaining in this partition          
}MEM_PARTITION;
/**
 * @brief the memory partition
 * 
 */

Typedef MEM_POOL_SETUP_TBL;

typedef struct {
   DWORD_T memBlkSize; // 块大小 >=2
   DWORD_T memNBlks; // 块数量
}MEM_POOL_SETUP_TBL;
/**
 * @brief the memory pool table
 * 
 */