当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


erlang iolist_to_iovec(IoListOrBinary)用法及代码示例


erlang:iolist_to_iovec(IoListOrBinary) -> iovec()
OTP 20.1
类型:
IoListOrBinary = iolist() | binary()

返回一个约韦茨由整数和二进制组成IoListOrBinary。当您想要展平 iolist 但不需要单个二进制文件时,此函数非常有用。这对于将数据传递给 nif 函数非常有用,例如enif_inspect_iovec或者进行更有效的消息传递。使用此函数的优点iolist_to_binary/1是它不必复制off-heap 二进制文件.例子:

> Bin1 = <<1,2,3>>.
<<1,2,3>>
> Bin2 = <<4,5>>.
<<4,5>>
> Bin3 = <<6>>.
<<6>>
%% If you pass small binaries and integers it works as iolist_to_binary
> erlang:iolist_to_iovec([Bin1,1,[2,3,Bin2],4|Bin3]).
[<<1,2,3,1,2,3,4,5,4,6>>]
%% If you pass larger binaries, they are split and returned in a form
%% optimized for calling the C function writev.
> erlang:iolist_to_iovec([<<1>>,<<2:8096>>,<<3:8096>>]).
[<<1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,...>>,
 <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   ...>>,
 <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...>>]

相关用法


注:本文由纯净天空筛选整理自erlang.org大神的英文原创作品 iolist_to_iovec(IoListOrBinary) -> iovec()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。