国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

VLC的block_t

2019-11-09 16:53:19
字體:
來源:轉載
供稿:網友

0 VLC的block_t

1 發現問題

payload 數據內存起始位置是p_buffer, 大小是i_buffer , block本身也有個內存起始位置 p_start , 大小i_size , 令人疑惑。

struct block_t{ block_t *p_next; uint8_t *p_buffer; /**< Payload start */ size_t i_buffer; /**< Payload length */ uint8_t *p_start; /**< Buffer start */ size_t i_size; /**< Buffer total size */ uint32_t i_flags; unsigned i_nb_samples; /* Used for audio */ mtime_t i_pts; mtime_t i_dts; mtime_t i_length; /* Rudimentary support for overloading block (de)allocation. */ block_free_t pf_release;};

2 init構造

構造時發現payload數據內存位置和block緩沖的內存位置初始化為一樣的。 大小值也是一樣的。

void block_Init( block_t *restrict b, void *buf, size_t size ){ /* Fill all fields to their default */ b->p_next = NULL; b->p_buffer = buf; b->i_buffer = size; b->p_start = buf; b->i_size = size; b->i_flags = 0; b->i_nb_samples = 0; b->i_pts = b->i_dts = VLC_TS_INVALID; b->i_length = 0;#ifndef NDEBUG b->pf_release = BlockNoRelease;#endif}

3 實際分配alloc

實際block分配的時候,占用了更多內存, 傳遞給p_start 和p_buffer的是跳過了block_t 大小(64字節)內存的內存地址; 相應的,i_size和i_buffer,也減少了 block_t大小。 如果用戶要求分配size大小,實際分配的是size+64字節+32(對齊)0+32(頭部填充)+32(尾部填充)=size+160(字節),block_t內部擁有的內存大小是size+96字節。

block_t *block_Alloc (size_t size){ /* 2 * BLOCK_PADDING: PRe + post padding */ const size_t alloc = sizeof (block_t)/*64*/ + BLOCK_ALIGN + (2 * BLOCK_PADDING) + size; if (unlikely(alloc <= size)) return NULL; block_t *b = malloc (alloc); if (unlikely(b == NULL)) return NULL; block_Init (b, b + 1, alloc - sizeof (*b)); static_assert ((BLOCK_PADDING % BLOCK_ALIGN) == 0, "BLOCK_PADDING must be a multiple of BLOCK_ALIGN"); b->p_buffer += BLOCK_PADDING + BLOCK_ALIGN - 1; b->p_buffer = (void *)(((uintptr_t)b->p_buffer) & ~(BLOCK_ALIGN - 1)); b->i_buffer = size; b->pf_release = block_generic_Release; return b;}

4 最后還要對齊和調整

參考 [http://blog.csdn.net/fuzhuo233/article/details/8182335] 線性內存分配器的實現 /TODO/

static_assert ((BLOCK_PADDING % BLOCK_ALIGN) == 0, "BLOCK_PADDING must be a multiple of BLOCK_ALIGN"); b->p_buffer += BLOCK_PADDING + BLOCK_ALIGN - 1; b->p_buffer = (void *)(((uintptr_t)b->p_buffer) & ~(BLOCK_ALIGN - 1));

payload的緩沖b->p_buffer 還是要后移然后對齊 payload的緩沖大小 還是要等于用戶需要的size大小。 那這樣的話,block的緩沖地址start和size就與payload的區分開了。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 扎兰屯市| 革吉县| 时尚| 洪洞县| 阿城市| 岳普湖县| 丹巴县| 蕉岭县| 丹东市| 太和县| 罗城| 六安市| 磐石市| 新沂市| 合水县| 苏尼特左旗| 萍乡市| 富平县| 浙江省| 铁岭县| 固始县| 邯郸县| 平乡县| 沈阳市| 新沂市| 富顺县| 遂川县| 蓝田县| 呼和浩特市| 东阿县| 大丰市| 正阳县| 武胜县| 高陵县| 寿宁县| 九龙城区| 德阳市| 勐海县| 汉寿县| 分宜县| 滨州市|