# What are the main differences between RawArray and PackedArray?

What I know:

• PackedArray is documented (to some extent) in "Developer Utilities Package", RawArray is just mentioned in Raster3D and ImageApply,

• RawArray supports Byte, SignedInteger8/16/32, Bit16, Real32, Real and Complex128 as entries, while PackedArray only Integer, Real and Complex(128),

• PackedArray displays as a list but RawArray as (somewhat of) a skeleton.

What I do not understand is why there are two of them. Why not just stick with the one that supports more entry types and display it as skeleton if and only if it is too long?

Also, how does ByteArray fit into the picture?

Edit: You can create a PackedArray using:

ap = DeveloperToPackedArray[{1, 2, 3}]
(* {1,2,3} *)
DeveloperPackedArrayQ[ap]
(* True *)
DeveloperPackedArrayForm[ap]
(* PackedArray[Integer, <3>] *)

(Note that there is in fact no PackedArray command, the head of the last output expression is a string.)

You can create a RawArray using:

ar = DeveloperAllocateRawArray["Byte", {2, 2}]
(* RawArray[Byte, <2,2>] *)
DeveloperRawArrayQ[ar]
(* True *)
DeveloperRawArrayType[ar]
(* Byte *)

You can create a ByteArray directly:

ab = ByteArray[{1,2,3}]
(* ByteArray[<3>] *)
ByteArrayQ[ab]
(* True *)

All the cross-tests (e.g., RawArrayQ done on ab) return False.

• no idea what this means, but according to ByteCount both packed and raw arrays use at least 8 bytes per value, even with the "Byte" type explicitly called out. ByteArray uses the expected one byte per value. The raw array seems to be always exactly 96 bytes bigger than the packed array. – george2079 Mar 16 '16 at 19:02
• PackedArray can't use bytes, 8 bytes is the word size on a 64-bit machine so that makes sense. RawArray works well for me: ar = Developer`AllocateRawArray["Byte", {10000}]; ByteCount[ar] gives just a little over 10000. It's 176 rather than 96 bytes of overhead on my computer. – The Vee Mar 16 '16 at 19:04
• I see. I was doing AllocateRawArray["Byte", *biglist* ] which is invalid so just getting the size of the list. – george2079 Mar 16 '16 at 19:20
• @george2079 instead of *biglist* you should use a dimension specification, e.g. {40,50} is a 40 by 50 matrix. – Szabolcs Mar 17 '16 at 11:36
• yes i figured that out. I should add on my machine ByteCount and MemoryInUse indicate hardly any memory usage after "allocating" a large array. – george2079 Mar 17 '16 at 12:27