Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #5110
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: 64-bit bytes |
| References | (9 earlier) <y%Osw.742376$MH.437411@fx12.am4> <874mrwmazc.fsf@ixod.org> <87lhl8t7a2.fsf@bsb.me.uk> <KXQsw.1051659$il4.619865@fx06.am4> <1wjz2viojajea.1kr9ibzhhn9v7.dlg@40tude.net> |
| Message-ID | <oITsw.567851$812.424728@fx20.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2015-01-12 17:42 +0000 |
On 12/01/2015 15:35, Dmitry A. Kazakov wrote: > On Mon, 12 Jan 2015 14:34:17 +0000, BartC wrote: > >> On 12/01/2015 14:15, Ben Bacarisse wrote: > >>> Not knowing anything about Erlang I'm curious about the need to make any >>> assumption about bytes at all. Why does the function not return the >>> number of value bits? Surely that's both more flexible an just as >>> useful? > > In Ada all sizes are in bits. I thought you said elsewhere that integer types are defined as ranges, not how many bits they should occupy. >> The number of bytes must be more useful overall, it you wished to find >> out how much RAM is taken up by N words, or how much disk space, or the >> size of a record; you rarely do these calculation in bits. > > Ever heard about packed arrays, bit fields, Boolean? The following program: > > with Ada.Text_IO; use Ada.Text_IO; > procedure Test is > begin > Put_Line (Integer'Image (Boolean'Size) & " bit"); > end Test; > > prints: > > 1 bit > > How many bytes is that? 1/8? Obviously the number of bytes occupied for a single, isolated bit is not meaningful. (And the chances are that such a standalone bit variable will occupy a whole byte or word anyway.) You have to take these things into account. If I write in one my languages: println int.bytes println byte.bytes println bit.bytes I get: 4, 1 and 1. But if I write: println int.bitwidth println byte.bitwidth println bit.bitwidth Then I get 32, 8 and 1. If you created a function in Ada to return the size of a type in terms of 8-bit bytes, and the result had to be an integer, then you will get similar problems. In my case, I decided that rounding up was the most useful, considering for example that so many library functions work in whole bytes (I can't allocate 14.625 bytes, it has to be 15). With packed bit arrays, the number of bytes are also rounded up to whole bytes (but needs extra care when working with in-place bit-slices which are not aligned on a byte or word. However you rarely need to worry about this stuff as don't need think in terms of bytes.) -- Bartc
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
64-bit bytes fir <profesor.fir@gmail.com> - 2015-01-05 01:38 -0800
Re: 64-bit bytes robin.vowels@gmail.com - 2015-01-08 00:46 -0800
Re: 64-bit bytes fir <profesor.fir@gmail.com> - 2015-01-08 00:53 -0800
Re: 64-bit bytes robin.vowels@gmail.com - 2015-01-11 15:46 -0800
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 00:32 +0000
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 01:35 +0000
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 09:07 +0000
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 11:43 +0000
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 11:59 +0000
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 12:21 +0000
Re: 64-bit bytes Mark Carroll <mtbc@bcs.org> - 2015-01-12 12:36 +0000
Re: 64-bit bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-01-12 14:15 +0000
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 14:34 +0000
Re: 64-bit bytes "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-01-12 16:35 +0100
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 17:42 +0000
Re: 64-bit bytes "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-01-12 19:11 +0100
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 19:18 +0000
Re: 64-bit bytes "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-01-12 21:34 +0100
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 22:01 +0000
Re: 64-bit bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-01-13 00:51 +0000
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 13:18 +0000
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 14:16 +0000
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 14:48 +0000
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-12 15:05 +0000
Re: 64-bit bytes Robert Wessel <robertwessel2@yahoo.com> - 2015-01-12 15:43 -0600
Re: 64-bit bytes Kaz Kylheku <kaz@kylheku.com> - 2015-01-12 21:05 +0000
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 22:12 +0000
Re: 64-bit bytes "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-01-12 10:12 +0100
Re: 64-bit bytes robin.vowels@gmail.com - 2015-01-11 20:56 -0800
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 09:19 +0000
Re: 64-bit bytes robin.vowels@gmail.com - 2015-01-12 06:22 -0800
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-12 14:51 +0000
Re: 64-bit bytes robin.vowels@gmail.com - 2015-01-12 15:46 -0800
Re: 64-bit bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-01-13 01:16 +0000
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-13 01:53 +0000
Re: 64-bit bytes Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-01-13 13:28 +0000
Re: 64-bit bytes Richard Heathfield <invalid@see.sig.invalid> - 2015-01-13 13:57 +0000
Re: 64-bit bytes "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2015-01-13 15:32 +0100
Re: 64-bit bytes fir <profesor.fir@gmail.com> - 2015-01-13 06:33 -0800
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-13 16:41 +0000
Re: 64-bit bytes fir <profesor.fir@gmail.com> - 2015-01-13 15:25 -0800
Re: 64-bit bytes BartC <bc@freeuk.com> - 2015-01-13 23:49 +0000
Re: 64-bit bytes fir <profesor.fir@gmail.com> - 2015-01-13 23:57 -0800
csiph-web