1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */ 2 /* 3 * Copyright (c) 2015 Rockchip Electronics Co., Ltd. 4 */ 5 6 #ifndef __MPP_MEM_H__ 7 #define __MPP_MEM_H__ 8 9 #include <stdlib.h> 10 11 #include "rk_type.h" 12 #include "mpp_err.h" 13 14 #define mpp_malloc_with_caller(type, count, caller) \ 15 (type*)mpp_osal_malloc(caller, sizeof(type) * (count)) 16 17 #define mpp_malloc(type, count) \ 18 (type*)mpp_osal_malloc(__FUNCTION__, sizeof(type) * (count)) 19 20 #define mpp_malloc_size(type, size) \ 21 (type*)mpp_osal_malloc(__FUNCTION__, size) 22 23 #define mpp_calloc(type, count) \ 24 (type*)mpp_osal_calloc(__FUNCTION__, sizeof(type) * (count)) 25 26 #define mpp_calloc_size(type, size) \ 27 (type*)mpp_osal_calloc(__FUNCTION__, size) 28 29 #define mpp_realloc(ptr, type, count) \ 30 (type*)mpp_osal_realloc(__FUNCTION__, ptr, sizeof(type) * (count)) 31 32 #define mpp_realloc_size(ptr, type, size) \ 33 (type*)mpp_osal_realloc(__FUNCTION__, ptr, size) 34 35 #define mpp_free(ptr) \ 36 mpp_osal_free(__FUNCTION__, ptr) 37 38 #define MPP_FREE(ptr) do { if(ptr) mpp_free(ptr); ptr = NULL; } while (0) 39 #define MPP_FCLOSE(fp) do { if(fp) fclose(fp); fp = NULL; } while (0) 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 void *mpp_osal_malloc(const char *caller, size_t size); 46 void *mpp_osal_calloc(const char *caller, size_t size); 47 void *mpp_osal_realloc(const char *caller, void *ptr, size_t size); 48 void mpp_osal_free(const char *caller, void *ptr); 49 50 void mpp_show_mem_status(); 51 rk_u32 mpp_mem_total_now(); 52 rk_u32 mpp_mem_total_max(); 53 54 #ifdef __cplusplus 55 } 56 #endif 57 58 #endif /*__MPP_MEM_H__*/ 59 60