編輯:關於android開發
- #define MALLOC_OVERHEAD 8 //分配過程中,需要保留一部分額外的空間
- #define ALLOC_MAX_BLOCK_TO_DROP 4096 //後續會繼續分析該宏的用途
- #define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10 //後續會繼續分析該宏的用途
- #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
- #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
- #define ALLOC_ROOT_MIN_BLOCK_SIZE (MALLOC_OVERHEAD + sizeof(USED_MEM) + 8)
- /* Define some useful general macros (should be done after all headers). */
- #define MY_MAX(a, b) ((a) > (b) ? (a) : (b)) //求兩個數值之間的最大值
- #define MY_MIN(a, b) ((a) < (b) ? (a) : (b)) //求兩個數值之間的最小值
- typedef struct st_mem_root
- {
- USED_MEM *free; //free block link list的鏈表頭指針
- USED_MEM *used;//used block link list的鏈表頭指針
- USED_MEM *pre_alloc; //預先分配的block
- size_t min_malloc; //如果block剩下的可用空間小於該值,將會從free list移動到used list
- size_t block_size; //每次初始化的空間大小
- unsigned int block_num; //記錄實際的block數量,初始化為4
- unsigned int first_block_usage; //free list中的第一個block 測試不滿足分配空間大小的次數
- void (*error_handler)(void);//分配失敗的錯誤處理函數
- } MEM_ROOT;
其實MEM_ROOT在分配過程中,是通過雙向鏈表來管理used和free的block:
- typedef struct st_used_mem
- {
- struct st_used_mem *next; //指向下一個分配的block
- unsigned int left; //該block剩余的空間大小
- unsigned int size; //該block的總大小
- } USED_MEM;
- void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,size_t pre_alloc_size __attribute__((unused)))
- {
- mem_root->free= mem_root->used= mem_root->pre_alloc= 0;
- mem_root->min_malloc= 32;
- mem_root->block_size= block_size - ALLOC_ROOT_MIN_BLOCK_SIZE;
- mem_root->error_handler= 0;
- mem_root->block_num= 4; /* We shift this with >>2 */
- mem_root->first_block_usage= 0;
- }
- void *alloc_root(MEM_ROOT *mem_root, size_t length)
- {
- size_t get_size, block_size;
- uchar* point;
- reg1 USED_MEM *next= 0;
- reg2 USED_MEM **prev;
- length= ALIGN_SIZE(length);
- if ((*(prev= &mem_root->free)) != NULL)
- {
- if ((*prev)->left < length &&
- mem_root->first_block_usage++ >= ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP &&
- (*prev)->left < ALLOC_MAX_BLOCK_TO_DROP)
- {
- next= *prev;
- *prev= next->next; /* Remove block from list */
- next->next= mem_root->used;
- mem_root->used= next;
- mem_root->first_block_usage= 0;
- }
- for (next= *prev ; next && next->left < length ; next= next->next)
- prev= &next->next;
- }
- if (! next)
- { /* Time to alloc new block */
- block_size= mem_root->block_size * (mem_root->block_num >> 2);
- get_size= length+ALIGN_SIZE(sizeof(USED_MEM));
- get_size= MY_MAX(get_size, block_size);
- if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME | ME_FATALERROR))))
- {
- if (mem_root->error_handler)
- (*mem_root->error_handler)();
- DBUG_RETURN((void*) 0); /* purecov: inspected */
- }
- mem_root->block_num++;
- next->next= *prev;
- next->size= get_size;
- next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); //bug:如果該block是通過mem_root->block_size * (mem_root->block_num >> 2)計算出來的,則已經去掉了ALIGN_SIZE(sizeof(USED_MEM),這裡重復了。
- *prev=next;
- }
- point= (uchar*) ((char*) next+ (next->size-next->left));
- /*TODO: next part may be unneded due to mem_root->first_block_usage counter*/
- if ((next->left-= length) < mem_root->min_malloc)
- { /* Full block */
- *prev= next->next; /* Remove block from list */
- next->next= mem_root->used;
- mem_root->used= next;
- mem_root->first_block_usage= 0;
- }
- }
prev指向的是最後一個block的next指向的地址的地址:
- for (next= *prev ; next && next->left < length ; next= next->next)
- prev= &next->next;
- }
水滴效果的下拉刷新--第三方開源 開源--WaveSwipeRefreshLayout,swiperefreshlayout 下載地址:https://github.co
Android廣播BroadcastReceiver Android廣播BroadcastReceiver Android 系統裡定義了各種各樣的廣播
android OTA升級包制作,androidota升級包0.簽名 java -Xmx2048m -jar out/host/linux-x86/framework/s
讓服務器iis支持.apk文件下載的設置方法,iis.apk隨著智能手機的普及,越來越多的人使用手機上網,很多網站也應手機上網的需要推出了網站客戶端,.apk文件就是安卓