Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29118 > unrolled thread
| Started by | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| First post | 2014-07-18 11:51 -0700 |
| Last post | 2014-07-18 21:11 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
BitSet vs boolean[] Roedy Green <see_website@mindprod.com.invalid> - 2014-07-18 11:51 -0700
Re: BitSet vs boolean[] Robert Klemme <shortcutter@googlemail.com> - 2014-07-18 21:11 +0200
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-07-18 11:51 -0700 |
| Subject | BitSet vs boolean[] |
| Message-ID | <63ris9524feapq3fe288pv7lj1mdpoj444@4ax.com> |
In terms of minimising space, how big must a boolean array be before it pays to use a BitSet? -- Roedy Green Canadian Mind Products http://mindprod.com Science is what we understand well enough to explain to a computer. Art is everything else we do. ~ Donald Ervin Knuth (born: 1938-01-10 age: 76)
[toc] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2014-07-18 21:11 +0200 |
| Message-ID | <c2t9rfFg9d0U1@mid.individual.net> |
| In reply to | #29118 |
On 18.07.2014 20:51, Roedy Green wrote: > In terms of minimising space, how big must a boolean array be before > it pays to use a BitSet? Well, a BitSet has these members - long[] - int - boolean If I'm not mistaken that yields sizeof(ref) + 8 * length + 4 + 4 = sizeof(ref) + 8 * (length + 1) bytes with length > 0 so at least sizeof(ref) + 16 bytes. I'd say worst case this is 8 + 16 = 24 bytes. Sinze a BitSet grows dramatically slower (on average 8 times) than a byte array if you add items that should be the max size. Of course, you can save even more memory by using a byte, short, int or long if you know the max set size is 8, 16, 32 or 64 bits and implement all the operations via bit logic. Kind regards robert
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web