TempCache 临时内存缓存器

TempCache.h

/* ***************************************************
 * Copyright(c) Xiamen AutoNavi Company. Ltd.
 * All Rights Reserved.
 *
 * File: segl_multicache.h
 * Purpose: 复数内存块管理接口定义
 *
 * Author: wmh
 *
 *
 * Version:
 * Date: 24-Oct-2015 14:51:07
 * Update: Create
 *
 *************************************************** */

#ifndef SEGL_TEMPCACHE_H
#define SEGL_TEMPCACHE_H

#include "gtypes.h"
#include "segl_Def.h"
#include "segl_cvector.h"


#ifdef __cplusplus
extern "C"
{
#endif/*__cplusplus */
    #define DEFARG(name, defval) ((#name[0]) ? (name + 0) : defval)
    //超大内存1.3M
    #define SUPER_MEM_BLOCK_SIZE 1300000
    //大内存300K
    #define MAX_MEM_BLOCK_SIZE   300000
    //小内存分界线100K
    #define MIN_MEM_BLOCK_SIZE   100000
    #define SKIP_MEM_BLOCK_SIZE  20000
    typedef struct GSEGLTEMPCACHEMGR *GHSEGLTEMPCACHEMGR;
    typedef struct tagCVector *CVector;
    typedef struct tagTempCVector *TempCVector;
    
    /**
     **********************************************************************
     \brief   创建临时内存块管理器
     \details 创建临时内存块管理器
     \param[in] nBlockCnt 内存块个数
     \param[in] nFixedSize 单一内存块中不变内存大小
     \param[in] nUnFixedSize 单一内存块中变化内存期望大小
     \param[out] phSeglMultiCacheMgr 内存管理器
     \retval    GD_ERR_OK 成功
     \retval    GD_ERR_INVALID_PARAM 参数无效
     \retval    GD_ERR_NO_MEMORY 内存不足
     \since 8.0
     \see SEGL_DestroyCacheMgr
     \remark SEGL_DestroyCacheMgr成对调用,否则会内存泄漏
     **********************************************************************/
    GSTATUS SEGL_CreateTempCacheMgr(GHSEGLTEMPCACHEMGR *phSeglMultiCacheMgr,Gint32 nBlockCnt);
    
    /**
     **********************************************************************
     \brief   销毁内存块管理器
     \details 销毁内存块管理器
     \param[in] hSeglMultiCacheMgr 内存管理器
     \retval    GD_ERR_OK 成功
     \retval    GD_ERR_INVALID_PARAM 参数无效
     \since 8.0
     \see SEGL_CreateMultiCacheMgr
     \remark SEGL_CreateMultiCacheMgr成对调用,否则会内存泄漏
     **********************************************************************/
    GSTATUS SEGL_DestroyTempCacheMgr(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr);
    
    /**
     **********************************************************************
     \brief   清空内存块状态,但不释放内存
     \details 清空当前所有使用的内存块状态,释放内存管理器中占用空间超大的内存块,和释放过多的内存碎片
     \param[in] hSeglMultiCacheMgr 内存管理器
     \retval    GD_ERR_OK 成功
     \retval    GD_ERR_INVALID_PARAM 参数无效
     \since 8.0
     **********************************************************************/
    GSTATUS SEGL_ClearTempCacheMgr(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr);
    
    /**
     **********************************************************************
     \brief   获取指定空间的缓存对象
     \details 根据输入的参数获取指定内存大小的指针
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] nLen               数据的长度
     \param[in] nSize              单个元素占的空间大小
     \retval    分配好的内存指针
     \since 8.0
     **********************************************************************/
    Gint8*  SEGL_GetNewTempMemCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 nLen, Gint32 nSize);

    /**
     **********************************************************************
     \brief   获取指定空间的缓存空间指针
     \details 根据输入的参数获取指定内存大小的指针
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] nLen               数据的长度
     \param[in] nSize              单个元素占的空间大小
     \param[out] pnIdx             返回分配内存空间的索引号
     \retval    分配好的内存指针
     \since 8.0
     **********************************************************************/
    Gint8*  SEGL_GetNewTempMemCacheWithPos(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr,Gint32 nLen,Gint32 nSize,Gint32 *pnIdx);
     /**
     **********************************************************************
     \brief   获取指定空间的缓存对象
     \details 根据输入的参数获取指定CVector对象
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] nLen               数据的长度
     \param[in] nSize              单个元素占的空间大小
     \param[out] pnIdx             返回分配内存空间的索引号
     \retval    分配好的内存指针
     \since 8.0
     **********************************************************************/
    CVector SEGL_GetNewTempCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 nLen, Gint32 nSize);
    /**
     **********************************************************************
     \brief   回收缓存对象
     \details 将输入的对象所占用的内存回收分配给其它模块
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] pstCVector         需要回收的CVector对象
     \retval    GD_ERR_OK  操作成功
                GD_ERR_INVALID_PARAM 参数无效
                GD_ERR_FAILED 操作失败
     \since 8.0
     **********************************************************************/
    GSTATUS SEGL_RemoveTempCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, CVector pstCVector);
    
    /**
     **********************************************************************
     \brief   获取指定的CVector对象
     \details 根据输入的参数,获取指定的CVector对象
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] nIdx               所要获取的位置
     \retval    返回指定的CVector对象
     \since 8.0
     **********************************************************************/
    CVector SEGL_AtTempCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 nIdx);

    /**
     **********************************************************************
     \brief   获取指定的内存对象
     \details 根据输入的参数,获取指定的内存对象
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] nIdx               所要获取的位置
     \param[out] pnLen             返回内存块所占的空间
     \retval    返回指定的内存对象指针
     \since 8.0
     **********************************************************************/
    Gint8* SEGL_AtTempMemCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 nIdx,Gint32 * pnLen);
    
    /**
     **********************************************************************
     \brief   回收缓存对象
     \details 将输入的指针所占用的内存回收
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] pvMemCache         需要回收内存块
     \retval    GD_ERR_OK  操作成功
     GD_ERR_INVALID_PARAM 参数无效
     GD_ERR_FAILED 操作失败
     \since 8.0
     **********************************************************************/
    GSTATUS SEGL_RemoveTempMemCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint8* pvMemCache);

    /**
     **********************************************************************
     \brief   回收缓存对象
     \details 将输入的指针所占用的内存回收
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] nIdx               需要对象的索引ID
     \retval    GD_ERR_OK  操作成功
     GD_ERR_INVALID_PARAM 参数无效
     GD_ERR_FAILED 操作失败
     \since 8.0
     **********************************************************************/
    GSTATUS SEGL_RemoveTempCache_Idx(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 nIdx);
    /**
     **********************************************************************
     \brief   获取指定CVector的缓存对象
     \details 根据输入的参数获取指定内存大小的指针
     \param[in] hSeglMultiCacheMgr 内存管理器
     \param[in] nLen               数据的长度
     \param[in] nSize              单个元素占的空间大小
     \param[out] pnIdx             返回分配内存空间的索引号
     \retval    分配好的内存指针
     \since 8.0
     **********************************************************************/
    CVector SEGL_GetNewTempCacheWithPos(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr,Gint32 nLen,Gint32 nSize,Gint32 *pnIdx);
    //Debug结果输出
    void SEGL_TempCachePrintf(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr);
    
#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif // ! SEGL_MULTICACHE_H

 

TempCache.c

  1 /* ***************************************************
  2  * Copyright(c) Xiamen AutoNavi Company. Ltd.
  3  * All Rights Reserved.
  4  *
  5  * File: segl_multicache.c
  6  * Purpose: 复数内存块管理接口实现
  7  *
  8  * Author: wmh
  9  *
 10  *
 11  * Version:
 12  * Date: 24-Oct-2015 14:51:07
 13  * Update: Create
 14  *
 15  *************************************************** */
 16 
 17 #include "segl_tempcache.h"
 18 #include "segl_utils.h"
 19 #include "libgdc.h"
 20 //#include "segl_cvector.h"
 21 //#include <android/log.h>
 22 //#define TAG "wmh"
 23 /**
 24  * 缓存管理
 25  */
 26 typedef struct GSEGLTEMPCACHEMGR
 27 {
 28     Gint32 nUsedBlockIdx;              /**< 当前所使用到内存块个数 */
 29     Gint32 nUsedBlockCnt;              /**< 可用内存块总数 */
 30     CVector ptList;                    /**< 定长内存列表 */
 31 }GSEGLTEMPCACHEMGR;
 32 
 33 typedef struct tagTempCVector
 34 {
 35     struct tagCVector base;//CVector对象
 36     Gint32 nUseEnable;//是否使用
 37 }tagTempCVector;
 38 
 39 
 40 /**
 41  **********************************************************************
 42  \brief 创建临时内存块管理器
 43  \details 创建临时内存块管理器
 44  \param[in] nBlockCnt 内存块个数
 45  \param[out] phSeglMultiCacheMgr 内存管理器
 46  \retval    GD_ERR_OK 成功
 47  \retval    GD_ERR_INVALID_PARAM 参数无效
 48  \retval    GD_ERR_NO_MEMORY 内存不足
 49  \since 8.0
 50  \see SEGL_DestroyCacheMgr
 51  \remark SEGL_DestroyCacheMgr成对调用,否则会内存泄漏
 52  **********************************************************************/
 53 GSTATUS SEGL_CreateTempCacheMgr(GHSEGLTEMPCACHEMGR *phSeglMultiCacheMgr,Gint32 nBlockCnt)
 54 {
 55     GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr = GNULL;
 56     CVECTORSTATUS euCVStatus = CV_ERR_OK;
 57     
 58     if ((phSeglMultiCacheMgr == GNULL) || (nBlockCnt <= 0) || *phSeglMultiCacheMgr != GNULL)
 59     {
 60         return(GD_ERR_INVALID_PARAM);
 61     }
 62     *phSeglMultiCacheMgr = GNULL;
 63     
 64     hSeglMultiCacheMgr = (GHSEGLTEMPCACHEMGR)Gmalloc(sizeof(GSEGLTEMPCACHEMGR));
 65     if (hSeglMultiCacheMgr == GNULL)
 66     {
 67         return(GD_ERR_NO_MEMORY);
 68     }
 69     Gmemset(hSeglMultiCacheMgr, 0, sizeof(GSEGLTEMPCACHEMGR));
 70     hSeglMultiCacheMgr->ptList=(CVector)Gmalloc(sizeof(tagCVector));
 71     Gmemset(hSeglMultiCacheMgr->ptList, 0, sizeof(tagCVector));
 72     euCVStatus = CVector_Create(hSeglMultiCacheMgr->ptList,nBlockCnt,sizeof(tagTempCVector));
 73 
 74     if (euCVStatus != CV_ERR_OK)
 75     {
 76         SEGL_DestroyTempCacheMgr(hSeglMultiCacheMgr);
 77         return(GD_ERR_FAILED);
 78     }
 79     hSeglMultiCacheMgr->nUsedBlockIdx = 0;
 80     hSeglMultiCacheMgr->nUsedBlockCnt = 0;//by wmh
 81     *phSeglMultiCacheMgr = hSeglMultiCacheMgr;
 82     return(GD_ERR_OK);
 83 }
 84 
 85 /**
 86  **********************************************************************
 87  \brief 摧毁复数内存块管理器
 88  \details 摧毁复数内存块管理器
 89  \param[in] hSeglMultiCacheMgr 内存管理器
 90  \retval    GD_ERR_OK 成功
 91  \retval    GD_ERR_INVALID_PARAM 参数无效
 92  \since 8.0
 93  \see SEGL_CreateMultiCacheMgr
 94  \remark SEGL_CreateMultiCacheMgr成对调用,否则会内存泄漏
 95  **********************************************************************/
 96 GSTATUS SEGL_DestroyTempCacheMgr(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr)
 97 {
 98     Gint32 i = 0;
 99     TempCVector pstCVector = GNULL;
100     if (hSeglMultiCacheMgr == GNULL)
101     {
102         return(GD_ERR_INVALID_PARAM);
103     }
104     if (hSeglMultiCacheMgr->ptList != GNULL)
105     {
106         if (hSeglMultiCacheMgr->ptList->cv_pdata != GNULL)
107         {
108             for (i = 0; i < hSeglMultiCacheMgr->nUsedBlockCnt; i++)
109             {
110                 pstCVector = CVector_At_Idx(hSeglMultiCacheMgr->ptList, i);
111                 CVector_Destroy((CVector)pstCVector);
112                 pstCVector->nUseEnable=0;
113             }
114             CVector_Destroy(hSeglMultiCacheMgr->ptList);
115         }
116         Gfree(hSeglMultiCacheMgr->ptList);
117         hSeglMultiCacheMgr->ptList = GNULL;
118     }
119    
120     Gfree(hSeglMultiCacheMgr);
121     hSeglMultiCacheMgr = GNULL;
122     return(GD_ERR_OK);
123 }
124 
125 /**
126  **********************************************************************
127  \brief   清空内存块管理器,但不释放内存
128  \details 清空内存块管理器,但不释放内存
129  \param[in] hSeglMultiCacheMgr 内存管理器
130  \retval    GD_ERR_OK 成功
131  \retval    GD_ERR_INVALID_PARAM 参数无效
132  \since 8.0
133  \see SEGL_CreateMultiCacheMgr
134  \remark SEGL_CreateMultiCacheMgr成对调用,否则会内存泄漏
135  **********************************************************************/
136 GSTATUS SEGL_ClearTempCacheMgr(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr)
137 {
138     Gint32 i = 0;
139     Gint32 MaxMemIdx = -1;
140     TempCVector pstCVector = GNULL;
141     CVector  pstMaxCVector = GNULL;
142     if (hSeglMultiCacheMgr == GNULL)
143     {
144         return(GD_ERR_INVALID_PARAM);
145     }
146     //__android_log_print(ANDROID_LOG_INFO, TAG, "SEGL_ClearTempCacheMgr S");
147     //SEGL_TempCachePrintf(hSeglMultiCacheMgr);
148     hSeglMultiCacheMgr->nUsedBlockIdx = 0;
149     if (hSeglMultiCacheMgr->ptList != GNULL)
150     {
151         if (hSeglMultiCacheMgr->ptList->cv_pdata != GNULL)
152         {
153             for (i = 0; i < hSeglMultiCacheMgr->nUsedBlockCnt; i++)
154             {
155                 pstCVector = CVector_At_Idx(hSeglMultiCacheMgr->ptList, i);
156                 pstCVector->nUseEnable = 0;
157                 if (pstMaxCVector == GNULL || pstMaxCVector->cv_tot_len < pstCVector->base.cv_tot_len)
158                 {
159                     if (pstMaxCVector != GNULL && pstMaxCVector->cv_tot_len > MAX_MEM_BLOCK_SIZE)
160                     {
161                         CVector_Destroy((CVector)pstMaxCVector);
162                     }
163                     MaxMemIdx = i;
164                     pstMaxCVector = (CVector)pstCVector;
165                 }
166                 else if (i > 3 || pstCVector->base.cv_tot_len > MAX_MEM_BLOCK_SIZE)
167                 {
168                     CVector_Destroy((CVector)pstCVector);
169                 }
170             }
171             if (pstMaxCVector != GNULL && pstMaxCVector->cv_tot_len > SUPER_MEM_BLOCK_SIZE)
172             {    //当内存超大时将释放
173                 CVector_Destroy((CVector)pstMaxCVector);
174             }
175         }
176     }
177     //SEGL_TempCachePrintf(hSeglMultiCacheMgr);
178     return(GD_ERR_OK);
179 }
180 Gint8* SEGL_GetNewTempMemCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr,Gint32 length, Gint32 size)
181 {
182     return SEGL_GetNewTempMemCacheWithPos( hSeglMultiCacheMgr, length, size, GNULL);
183 }
184 //获取指定内存缓存区
185 Gint8* SEGL_GetNewTempMemCacheWithPos(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 length, Gint32 size, Gint32 *pPos)
186 {
187     CVector vector = SEGL_GetNewTempCacheWithPos(hSeglMultiCacheMgr,length,size,pPos);
188     if(vector == GNULL)
189     {
190         return GNULL;
191     }
192     return vector->cv_pdata;
193 }
194 //获取指定Vector
195 CVector SEGL_GetNewTempCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr,Gint32 length,Gint32 size){
196     return SEGL_GetNewTempCacheWithPos(hSeglMultiCacheMgr, length, size, GNULL);
197 }
198 
199 //获取最合理的Vector对象
200 TempCVector GetTempVectorCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 length,Gint32 size)
201 {
202     Gint32  i=0;
203     TempCVector pstTmpVector = GNULL;
204     TempCVector pstRetVector = GNULL;
205     Gint32  nCurrentDiffSize=0;
206     Gint32  nDiffSize=0;
207     Gint32  nCurrentTotalSize=length*size;
208     
209     for(i = 0;i < hSeglMultiCacheMgr->nUsedBlockCnt;i++)
210     {
211         pstTmpVector = (TempCVector)CVector_At_Idx(hSeglMultiCacheMgr->ptList, i);
212         if (pstTmpVector->nUseEnable ==0)
213         {
214             nDiffSize=pstTmpVector->base.cv_tot_len-nCurrentTotalSize;
215             if(nCurrentTotalSize < MAX_MEM_BLOCK_SIZE)
216             { //小内存分配
217                 if(nDiffSize > 0 && nDiffSize < SKIP_MEM_BLOCK_SIZE)
218                 {   //空间够时判断
219                     //索引差值小于10K.将当前数据块分配给当前模块
220                     if(pstRetVector ==  GNULL)
221                     { //未分配内存
222                         pstRetVector = pstTmpVector;
223                         nCurrentDiffSize = nDiffSize;
224                     }
225                     else if(nCurrentDiffSize > nDiffSize )
226                     { //有更合适的内存
227                         pstRetVector = pstTmpVector;
228                         nCurrentDiffSize = nDiffSize;
229                     }
230                 }
231                 else
232                 {   //未分配到内存
233                     if (pstRetVector == GNULL)
234                     {
235                         pstRetVector = pstTmpVector;
236                         nCurrentDiffSize = nDiffSize;
237                     }
238                     else if (nDiffSize > 0 && nCurrentDiffSize < nDiffSize)
239                     {
240                         //使用最合理的内存分配器
241                         pstRetVector = pstTmpVector;
242                         nCurrentDiffSize = nDiffSize;
243                     }
244                 }
245             }
246             else
247             {// 大内存分配
248                 if(pstRetVector ==  GNULL)
249                 {
250                     pstRetVector = pstTmpVector;
251                     nCurrentDiffSize = nDiffSize;
252                 }
253                 else if(nCurrentDiffSize < nDiffSize )
254                 {   //使用最大的内存分配器
255                     pstRetVector = pstTmpVector;
256                     nCurrentDiffSize = nDiffSize;
257                 }
258             }
259         }
260     }
261     return pstRetVector;
262 }
263 //获取指定Vector
264 CVector SEGL_GetNewTempCacheWithPos(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr,Gint32 length,Gint32 size,Gint32 *poPos){
265     
266     TempCVector pstTmpVector = GNULL;
267     Gint32  stats = 0;
268 
269     if(hSeglMultiCacheMgr == GNULL || hSeglMultiCacheMgr->ptList == GNULL || size <= 0 )
270     {
271         return GNULL;
272     }
273     if (length <= 0)
274     {
275         length = 1;//最少创建一个元素
276     }
277      GLOG_POI_DEBUG(GT("SEGL_GetNewTempCacheWithPos len=%d ,size =%d\n"),length,size);
278     if(hSeglMultiCacheMgr->nUsedBlockIdx+1<hSeglMultiCacheMgr->nUsedBlockCnt)
279     {//返回已经存在的缓存
280         pstTmpVector = GetTempVectorCache(hSeglMultiCacheMgr,length,size);
281         if (pstTmpVector != GNULL)
282         {
283             stats = CVector_Resize(&(pstTmpVector->base),length,size);
284             if(stats != CVESUCCESS)
285             {
286                 return GNULL;
287             }
288             pstTmpVector->base.cv_struct = CV_TEMP_STRUCT;
289             pstTmpVector->nUseEnable = 1;
290             CVector_Clear(&(pstTmpVector->base));
291             if(poPos != GNULL)
292             {
293                 *poPos = CVector_At(hSeglMultiCacheMgr->ptList,pstTmpVector);
294             }
295             hSeglMultiCacheMgr->nUsedBlockIdx++;
296             return &(pstTmpVector->base);
297         }
298     }
299 
300     {//创建新的缓存区
301 
302         pstTmpVector= (TempCVector)CVector_NewEmpty(hSeglMultiCacheMgr->ptList);
303         stats = CVector_Create(&(pstTmpVector->base),length,size);
304 
305         if(stats == CVESUCCESS)
306         {
307             pstTmpVector->base.cv_struct = CV_TEMP_STRUCT;
308             hSeglMultiCacheMgr->nUsedBlockCnt++;
309             pstTmpVector->nUseEnable = 1;
310             hSeglMultiCacheMgr->nUsedBlockIdx++;
311             // added by dongliang.huang 2016.06.22
312             if (poPos != GNULL)
313             {
314                 *poPos = hSeglMultiCacheMgr->nUsedBlockCnt - 1;
315             }
316             return &(pstTmpVector->base);
317         }
318         else
319         {
320             CVector_Popback(hSeglMultiCacheMgr->ptList);
321         }
322     }
323        // printf("1.SEGL_GetNewTempCache start size=%d\n",CVector_Length(hSeglMultiCacheMgr->ptList));
324     // printf("getNewTempCache start nUsedBlockIdx=%d addr=%d,cv_pdata=%d,cv_len=%d,cv_size=%d,cv_tot_len=%d\n",hSeglMultiCacheMgr->nUsedBlockIdx,vector,vector->cv_pdata,vector->cv_len,vector->cv_size,vector->cv_tot_len);
325     return GNULL;
326 }
327 //回收内存块
328 GSTATUS SEGL_RemoveTempMemCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint8* array)
329 {
330     return SEGL_RemoveTempCache(hSeglMultiCacheMgr, (CVector)array);
331 }
332 //回收内存块
333 GSTATUS SEGL_RemoveTempCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, CVector pstCVector)
334 {
335     if(hSeglMultiCacheMgr == GNULL || pstCVector == GNULL)
336     {
337         return  GD_ERR_INVALID_PARAM;
338     }
339     if(pstCVector->cv_struct == CV_TEMP_STRUCT)
340     {
341         pstCVector->cv_size = 0;
342         pstCVector->cv_len  = 0;
343         ((TempCVector)pstCVector)->nUseEnable = 0;
344         
345         hSeglMultiCacheMgr->nUsedBlockIdx--;
346         return  CVESUCCESS;
347     }
348     else
349     {
350         return GD_ERR_FAILED;
351     }
352 }
353 //回收内存块
354 GSTATUS SEGL_RemoveTempCache_Idx(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 index)
355 {
356     TempCVector pstTmpVector = GNULL;
357     if(hSeglMultiCacheMgr == GNULL || index <0 || index >= CVector_Length(hSeglMultiCacheMgr->ptList))
358     {
359         return  GD_ERR_INVALID_PARAM;
360     }
361     pstTmpVector = (TempCVector)CVector_At_Idx(hSeglMultiCacheMgr->ptList, index);
362     return SEGL_RemoveTempCache(hSeglMultiCacheMgr, (CVector)pstTmpVector);
363 }
364 
365 //获取指定Vector
366 CVector SEGL_AtTempCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 index){
367 
368     if(hSeglMultiCacheMgr == GNULL || hSeglMultiCacheMgr->ptList == GNULL)
369     {
370         return GNULL;
371     }
372     if(hSeglMultiCacheMgr->nUsedBlockCnt > index){
373         return (CVector)CVector_At_Idx(hSeglMultiCacheMgr->ptList, index);
374     }
375     return  GNULL;
376 }
377 //获取指定内存缓存区
378 Gint8* SEGL_AtTempMemCache(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr, Gint32 index,Gint32 * pnLen)
379 {
380     CVector vector = SEGL_AtTempCache(hSeglMultiCacheMgr,index);
381     if(vector == GNULL)
382     {
383         return GNULL;
384     }
385     if(pnLen != GNULL)
386     {
387         *pnLen =vector->cv_tot_len;
388     }
389     return vector->cv_pdata;
390 }
391 
392 
393 void SEGL_TempCachePrintf(GHSEGLTEMPCACHEMGR hSeglMultiCacheMgr)
394 {
395 #ifdef GLOG_ON
396     Gint32 i=0;
397     Gint32 total = 0;
398     CVector cv=hSeglMultiCacheMgr->ptList;
399     CVector temp = GNULL;
400     GLOG_POI_DEBUG(GT("TempCachePrintf S Vector.tot_len=%d Vector.len=%d  nUsedBlockCnt =%d"),cv->cv_tot_len,CVector_Length(cv),hSeglMultiCacheMgr->nUsedBlockCnt);
401     for(i =0 ;i<CVector_Length(cv);i++)
402     {
403         temp= (CVector)CVector_At_Idx(cv, i);
404         GLOG_POI_DEBUG(GT("i=%d addr=%d,cv_pdata=%d,cv_len=%d,cv_size=%d,cv_tot_len=%d\n"),i,temp,temp->cv_pdata,temp->cv_len,temp->cv_size,temp->cv_tot_len);
405         //__android_log_print(ANDROID_LOG_INFO, TAG, "i=%d addr=%d,cv_pdata=%d,cv_tot_len=%d\n", i,temp,temp->cv_pdata,temp->cv_tot_len);
406         total += temp->cv_tot_len;
407     }
408     total = total;
409     GLOG_POI_DEBUG(GT("TempCachePrintf E tot_len=%d K"),total/1024);
410 #endif
411 }

 

转载于:https://www.cnblogs.com/wangmh/p/6596492.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值