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

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

VLC的block_t

2019-11-09 15:42:27
字體:
來源:轉載
供稿:網友

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的區分開了。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涟源市| 上栗县| 昌乐县| 安图县| 英德市| 深泽县| 丽水市| 延吉市| 巩留县| 应用必备| 贵南县| 谢通门县| 铜鼓县| 内江市| 凤凰县| 靖西县| 定州市| 成安县| 会宁县| 梓潼县| 巍山| 泸水县| 上犹县| 健康| 西丰县| 绥德县| 锡林浩特市| 临城县| 河源市| 同心县| 奉贤区| 会同县| 庆阳市| 玉田县| 旅游| 杂多县| 林州市| 西藏| 白城市| 虞城县| 永仁县|