Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2965675
  • 博文数量: 685
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5303
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-19 14:17
个人简介

文章分类

全部博文(685)

文章存档

2015年(116)

2014年(569)

分类: 嵌入式

2015-02-26 15:26:53

原文地址:http://blog.csdn.net/sunlion81/article/details/8818462
  1. #include   
  2. #include   
  3. #include  // for pj_init.  
  4.   
  5. #define THIS_FILE "main.c"  
  6.   
  7. int main(int argc, char** argv)  
  8. {  
  9.     pj_status_t status;  
  10.     pj_caching_pool ch_pool;  
  11.   
  12.     // pjlib库初始化  
  13.     status = pj_init();  
  14.     if (status != PJ_SUCCESS)  
  15.     {  
  16.         char errmsg[PJ_ERR_MSG_SIZE];  
  17.         pj_strerror(status, errmsg, sizeof(errmsg));  
  18.         PJ_LOG(1,(THIS_FILE, "%s: %s [status=%d]", pj_init, errmsg, status));  
  19.         return -1;  
  20.     }  
  21.   
  22.     // pjlib创建缓冲池工厂  
  23.     pj_caching_pool_init(&ch_pool, NULL, 1024*1024);  
  24.   
  25.     /* 分配内存示例 */  
  26.     {  
  27.         pj_pool_t *pool;  
  28.         pj_pool_factory *factory =&ch_pool.factory;  
  29.   
  30.         // 在分配内存前必须创建内存池  
  31.         pool = pj_pool_create(factory, "pjlib_demo", 4*1024, 4*1024, NULL);  
  32.         if (pool == NULL)  
  33.         {  
  34.             PJ_LOG(1,(THIS_FILE, "Error:pj_pool_create is NULL."));  
  35.             return PJ_ENOMEM;  
  36.         }  
  37.   
  38.         // 循环申请内存  
  39.         {  
  40.             int i;  
  41.             for (i=0; i<1000; i++)  
  42.             {  
  43.                 void* p;  
  44.                 p = pj_pool_alloc(pool, (pj_rand()+1) % 512);  
  45.             }  
  46.   
  47.             // 没有释放内存的函数!!!  
  48.         }  
  49.   
  50.         // 释放内存池  
  51.         pj_pool_release(pool);  
  52.     }  
  53.   
  54.     // pjlib销毁缓冲池工厂  
  55.     pj_caching_pool_destroy(&ch_pool);  
  56.   
  57.     // pjlib库关闭  
  58.     pj_shutdown();  
  59.   
  60.     return 0;  
  61. }  
阅读(926) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~