[MLton] bool array size

skaller skaller@users.sourceforge.net
Fri, 17 Mar 2006 12:38:01 +1100


On Thu, 2006-03-16 at 13:47 -0800, Stephen Weeks wrote:
> > Using the 20051201 version of MLton I see that an array of bools takes 4
> > bytes per entry (plus the array header).  Why isn't this 1 byte?  
> 
> This is a peformance bug.  The problem is unique to booleans, and
> doesn't show up with other enumerated types.  For example, the array
> in the following code will have one byte per element.


> Booleans are special because they appear in the FFI and hence their
> external representation is fixed (4 bytes, 0 = false, 1 = true).

Unfortunately that is actually wrong for C++ with g++.
C++ bool on gcc 4.x is 1 byte. Complete list calculated by
my config script on amd64 with gcc version 4.0 below, noting
please this is 64 bit machine but 32 bit representation will
be the same. Is there some other reason for making bool = int,
which is I guess what you're doing? C89 doesn't have boolean
type .. you can use 'char' is you like. Why choose int?

SIZEOF_BOOL=1
SIZEOF_CHAR=1
SIZEOF_COMPLEX=8
SIZEOF_DOUBLE=8
SIZEOF_DOUBLECOMPLEX=16
SIZEOF_ENUM=4
SIZEOF_FLOAT=4
SIZEOF_FUNCP=8
SIZEOF_INT=4
SIZEOF_INT16=2
SIZEOF_INT32=4
SIZEOF_INT64=8
SIZEOF_INT8=1
SIZEOF_LONG=8
SIZEOF_LONGDOUBLE=16
SIZEOF_LONGDOUBLECOMPLEX=32
SIZEOF_LONGLONG=8
SIZEOF_PTRDIFF=8
SIZEOF_SHORT=2
SIZEOF_SIZE=8
SIZEOF_UINT16=2
SIZEOF_UINT32=4
SIZEOF_UINT64=8
SIZEOF_UINT8=1
SIZEOF_VOIDP=8
SIZEOF_WCHAR=4


-- 
John Skaller <skaller at users dot sourceforge dot net>
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net