如何为 ByteString 创建 Ptr Word8
How to create a Ptr Word8 for ByteString
create, from Data.ByteString.Internal, states that it needs a Ptr Word8
in order to create a ByteString. I'm guessing this is like a reference to the head of the bytestring or something. However, I'm not sure what I should use to create a new pointer - I'm fairly sure it's not done properly with nullPtr.
不,create
给你一个指向要填充的内存的指针:
create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString
第一个参数是要创建的字节串的长度,第二个是一个函数,用于填充字节串。基本上 create
分配指定大小的内存缓冲区,然后使用指向缓冲区的指针调用函数。使用示例:
> create 5 $ \ptr -> pokeArray ptr [65, 66, 67, 68, 69]
"ABCDE"
create, from Data.ByteString.Internal, states that it needs a Ptr Word8
in order to create a ByteString. I'm guessing this is like a reference to the head of the bytestring or something. However, I'm not sure what I should use to create a new pointer - I'm fairly sure it's not done properly with nullPtr.
不,create
给你一个指向要填充的内存的指针:
create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString
第一个参数是要创建的字节串的长度,第二个是一个函数,用于填充字节串。基本上 create
分配指定大小的内存缓冲区,然后使用指向缓冲区的指针调用函数。使用示例:
> create 5 $ \ptr -> pokeArray ptr [65, 66, 67, 68, 69]
"ABCDE"