[MLton] bool array size
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?
John Skaller <skaller at users dot sourceforge dot net>
Async PL, Realtime software consultants
Checkout Felix: http://felix.sourceforge.net