ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 // Copyright 2017 Baidu Inc. All Rights Reserved.
TMBOY 47:9e361da97763 2 // Author: Su Hao (suhao@baidu.com)
TMBOY 47:9e361da97763 3 //
TMBOY 47:9e361da97763 4 // Description: The APIs for memory management.
TMBOY 47:9e361da97763 5
TMBOY 47:9e361da97763 6 #ifndef BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_MEMORY_H
TMBOY 47:9e361da97763 7 #define BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_MEMORY_H
TMBOY 47:9e361da97763 8
TMBOY 47:9e361da97763 9 #include "baidu_ca_types.h"
TMBOY 47:9e361da97763 10
TMBOY 47:9e361da97763 11 /*
TMBOY 47:9e361da97763 12 * malloc function
TMBOY 47:9e361da97763 13 *
TMBOY 47:9e361da97763 14 * @Param size, bca_size_t, the expected size of the memory
TMBOY 47:9e361da97763 15 * @Return the alloced memory pointer
TMBOY 47:9e361da97763 16 */
TMBOY 47:9e361da97763 17 BCA_INT void* bca_malloc(bca_size_t size);
TMBOY 47:9e361da97763 18
TMBOY 47:9e361da97763 19 /*
TMBOY 47:9e361da97763 20 * realloc function
TMBOY 47:9e361da97763 21 *
TMBOY 47:9e361da97763 22 * @Param ptr, void *, the old alloced memory
TMBOY 47:9e361da97763 23 * @Param size, bca_size_t, the expected size of the memory
TMBOY 47:9e361da97763 24 * @Return the new alloced memory pointer
TMBOY 47:9e361da97763 25 */
TMBOY 47:9e361da97763 26 BCA_INT void* bca_realloc(void* ptr, bca_size_t size);
TMBOY 47:9e361da97763 27
TMBOY 47:9e361da97763 28 /*
TMBOY 47:9e361da97763 29 * free function
TMBOY 47:9e361da97763 30 *
TMBOY 47:9e361da97763 31 * @Param ptr, void *, the alloced memory
TMBOY 47:9e361da97763 32 */
TMBOY 47:9e361da97763 33 BCA_INT void bca_free(void* ptr);
TMBOY 47:9e361da97763 34
TMBOY 47:9e361da97763 35 /*
TMBOY 47:9e361da97763 36 * malloc function
TMBOY 47:9e361da97763 37 *
TMBOY 47:9e361da97763 38 * @Param size, bca_size_t, the expected size of the memory
TMBOY 47:9e361da97763 39 * @Param file, const char *, the file name when alloc the memory
TMBOY 47:9e361da97763 40 * @Param line, bca_u32_t, the line number of the file when alloc the memory
TMBOY 47:9e361da97763 41 * @Return the alloced memory pointer
TMBOY 47:9e361da97763 42 */
TMBOY 47:9e361da97763 43 BCA_INT void* bca_malloc_ext(bca_size_t size, const char* file, bca_u32_t line);
TMBOY 47:9e361da97763 44
TMBOY 47:9e361da97763 45 /*
TMBOY 47:9e361da97763 46 * realloc function
TMBOY 47:9e361da97763 47 *
TMBOY 47:9e361da97763 48 * @Param ptr, void *, the old alloced memory
TMBOY 47:9e361da97763 49 * @Param size, bca_size_t, the expected size of the memory
TMBOY 47:9e361da97763 50 * @Param file, const char *, the file name when alloc the memory
TMBOY 47:9e361da97763 51 * @Param line, bca_u32_t, the line number of the file when alloc the memory
TMBOY 47:9e361da97763 52 * @Return the new alloced memory pointer
TMBOY 47:9e361da97763 53 */
TMBOY 47:9e361da97763 54 BCA_INT void* bca_realloc_ext(void* ptr, bca_size_t size, const char* file,
TMBOY 47:9e361da97763 55 bca_u32_t line);
TMBOY 47:9e361da97763 56
TMBOY 47:9e361da97763 57 /*
TMBOY 47:9e361da97763 58 * free function
TMBOY 47:9e361da97763 59 *
TMBOY 47:9e361da97763 60 * @Param ptr, void *, the alloced memory
TMBOY 47:9e361da97763 61 * @Param file, const char *, the file name when alloc the memory
TMBOY 47:9e361da97763 62 * @Param line, bca_u32_t, the line number of the file when alloc the memory
TMBOY 47:9e361da97763 63 */
TMBOY 47:9e361da97763 64 BCA_INT void bca_free_ext(void* ptr, const char* file, bca_u32_t line);
TMBOY 47:9e361da97763 65
TMBOY 47:9e361da97763 66 #ifdef BCA_MEMORY_USAGE
TMBOY 47:9e361da97763 67 BCA_INT void bca_memdbg_usage();
TMBOY 47:9e361da97763 68 #define BCA_MEMDBG_USAGE(...) bca_memdbg_usage()
TMBOY 47:9e361da97763 69 #else
TMBOY 47:9e361da97763 70 #define BCA_MEMDBG_USAGE(...)
TMBOY 47:9e361da97763 71 #endif
TMBOY 47:9e361da97763 72
TMBOY 47:9e361da97763 73 #ifdef BCA_MEMORY_DEBUG
TMBOY 47:9e361da97763 74 #define BCA_MALLOC(_s) bca_malloc_ext(_s, __FILE__, __LINE__)
TMBOY 47:9e361da97763 75 #define BCA_REALLOC(_p, _s) bca_realloc_ext(_p, _s, __FILE__, __LINE__)
TMBOY 47:9e361da97763 76 #define BCA_FREE(_p) bca_free_ext(_p, __FILE__, __LINE__)
TMBOY 47:9e361da97763 77 #else/*BCA_MEMORY_DEBUG*/
TMBOY 47:9e361da97763 78 #define BCA_MALLOC(_s) bca_malloc(_s)
TMBOY 47:9e361da97763 79 #define BCA_REALLOC(_p, _s) bca_realloc(_p, _s)
TMBOY 47:9e361da97763 80 #define BCA_FREE(_p) bca_free(_p)
TMBOY 47:9e361da97763 81 #endif/*BCA_MEMORY_DEBUG*/
TMBOY 47:9e361da97763 82
TMBOY 47:9e361da97763 83 #define BCA_CALLOC(_s, _n) BCA_MALLOC((_s) * (_n))
TMBOY 47:9e361da97763 84
TMBOY 47:9e361da97763 85 #endif // BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_MEMORY_H