0

So I before had this:

public static final boolean opaqueCubeLookup = new boolean[4096];

But I found out that BitSet it much better at managing memory, so I changed it to this:

public static final BitSet opaqueCubeLookup = new BitSet(4096);

I also had this code:

opaqueCubeLookup[par1] = this.isOpaqueCube();

But after moving to BitSet I have problem, I get this error:

The type of the expression must be an array type but it resolved to BitSet

How can I fix it? Any help is appreciated!

tambre
  • 4,625
  • 4
  • 42
  • 55
  • Note that according to [this](http://stackoverflow.com/a/605451/2071828) SO answer `BitSet` is significantly slower (4x). Swings and roundabouts eh? – Boris the Spider Mar 16 '13 at 11:09
  • @bmorris591 Is 4096 objects considered small, cause after some testing it seems to have 2x less FPS but takes less CPU and memory (I mean the optimized seems slower) – tambre Mar 16 '13 at 11:16
  • In the linked thread the benchmark is done with 1 million items, the post says that performance is equal when this reaches 4 million. I guess that means 4096 is (very) small... – Boris the Spider Mar 16 '13 at 12:26

2 Answers2

4
opaqueCudeLookup.set(par1, this.isOpaqueCube());

See BitSet.html#set(int, boolean)

Alexander Torstling
  • 18,552
  • 7
  • 62
  • 74
  • Thanks, this worked! Should boost my app perfomance a lot! :) – tambre Mar 16 '13 at 11:07
  • 1
    @tambre performance, no - it will be slower. Memory footprint will be less however. – Boris the Spider Mar 16 '13 at 11:11
  • @bmorris591 Just noticed it...Damn! I spent over 1hour converting it! – tambre Mar 16 '13 at 11:17
  • 1
    @tambre: In order to facilitate switching, make an interface with two implementations: one backed by a BitSet and one backed by a bool array. This way you can switch without so much effort. – Alexander Torstling Mar 16 '13 at 11:25
  • @bmorris591: I wouldn't assume that, though it's quite possible. Improved memory caching effects, for example, might outweigh the cost of the bit-twiddling -- if an entire `BitSet` fits into your L1 cache, where a `boolean[]` would not, then it's not at all clear which would win. – Louis Wasserman Mar 16 '13 at 16:38
0

Use:

opaqueCubeLookup.set(part1, this.isOpaqueCube());
Eyal Schneider
  • 22,166
  • 5
  • 47
  • 78