上次测试不太完善,得出错误的结论3.位数组的空间不是字节,而是双字节
其实BitAarry在0.51版文档中有详细说明。

BitArrays
BitArrays are space-efficient “packed” boolean arrays, which store one bit per boolean value. They can be used similarly to Array{Bool} arrays (which store one byte per boolean value), and can be converted to/from the latter via Array(bitarray) and BitArray(array), respectively.

• Vector (a.k.a. 1-dimensional Array)
• BitVector (a.k.a. 1-dimensional BitArray)

那就是说1维BitArray与BitVector实质上是一样的。在0.6版的联机帮助中:

help?> BitVector
search: BitVector

  BitArray(dims::Integer...)
  BitArray{N}(dims::NTuple{N,Int})

BitArray结构需要占用一定的基本空间。在元素较少的时候,也要至少8字节。

julia> map(x->(x,sizeof(BitArray(x))),[1,2,4,8,16,32,64,128,256])
9-element Array{Tuple{Int32,Int32},1}:
 (1, 8)
 (2, 8)
 (4, 8)
 (8, 8)
 (16, 8)
 (32, 8)
 (64, 8)
 (128, 16)
 (256, 32)

文档说Array构造函数返回的是未初始化的值,

Array(dims)
Array{T}(dims) constructs an uninitialized dense array with element type T. dims may be a tuple or a series of integer arguments. The syntax Array(T, dims) is also available, but deprecated.

联机帮助也是

help?> BitArray   
search: BitArray

  BitArray(dims::Integer...)  
  BitArray{N}(dims::NTuple{N,Int})  

  Construct an uninitialized BitArray with the given dimensions. Behaves identically to the Array constructor.  

在实际操作中,Array明显返回不确定的值。

julia> Array(Int8,10),Array(Int16,10)
(Int8[-32, 78, 7, 19, -112, 74, 10, 15, -16, 78], Int16[66, 0, 105, 0, 116, 0, 65, 0, 114, 0])

虽然BitArray观察到的都是false,为了确保得到需要的值,还是用trues和false保险。

julia> BitArray(10),trues(10),falses(10)
(Bool[false, false, false, false, false, false, false, false, false, false], 
Bool[true, true, true, true, true, true, true, true, true, true], 
Bool[false, false, false, false, false, false, false, false, false, false])

0.5版的联机帮助中显示BitArray有len成员,实际测试Aarry没有。

julia> BitArray(2, 2)
2××2 BitArray{2}:
 false  false
 false  false

julia> BitArray(3, 1)
3××1 BitArray{2}:
 false
 false
 false

julia> ba=BitArray(30);

julia> ba.len
30

julia> ia=Array{Int}(30);

julia> ia.len
ERROR: type Array has no field len