let reader = selectCommand.ExecuteReader()
let getBytesData (x : IDataReader) =
let len = reader.GetBytes(1, int64 0, null, 0, 0);
// Create a buffer to hold the bytes, and then
// read the bytes from the DataTableReader.
let buffer : byte array = Array.zeroCreate (int32 len)
x.GetBytes(1, int64 0, buffer, 0, int32 len) |> ignore
buffer
let retVal =
List [ while reader.Read() do
yield (reader.GetString(0), getBytesData reader,
reader.GetDateTime(2)) ]
我有上面的代码从datareader读取字节[]。F#与DataReader配合使用
getBytesData函数将读取器读取并返回来自reader的字节[]。
- 一切工作正常,但它getBytesData函数工作非常无功能的方式。
- 我很创建零填充的字节数组只是创建数组,是有创建动态扩张或固定lenght阵列
的任何方式有什么办法,我可以在F#优化?
对不起样的问题,但我已经开始对F#一个新的项目,以榨取所有果汁出来的,所以试图让每一行最优化的方式
使用零初始化数组是没有问题的 - 所有CLR数组始终在分配零初始化,没有选项来获得一个未初始化一个为“填写“后。 – 2010-06-07 04:20:37