- Code: Select all
private static Polje[][][] mreza = new Polje[2][30][30];
for (byte x = 0; x < mreza[0].length; x++)
{
for (byte y = 0; y < mreza[0][0].length; y++)
{
mreza[0][x][y] = new Polje(false, x, y);
mreza[1][x][y] = new Polje(true, x, y);
System.out.println(Runtime.getRuntime().freeMemory());
LCD.refresh();
Delay.msDelay(2000);
}
}
- Code: Select all
public class Polje implements Transmittable {
public TipPolja tip;
byte x;
byte y;
byte razdalja;
BitSet biti;
public Polje(Boolean zgoraj, byte x, byte y)
{
biti = new BitSet(8);
biti.clear();
biti.set(4, zgoraj);
this.x = x;
this.y = y;
tip = TipPolja.NERAZISKANO;
}
- Code: Select all
public enum TipPolja {
NERAZISKANO,
PREVOZENO,
CRNO;
}
(Sorry for weird looking names, they are not in english).
However, it will throw out of memory error. So I have decided to print out free memory to figure out, how much memory each Polje takes.
After each run of loop, there is 88 bytes less free memory. Loop initializes two objects, so that means that size of 1 Polje is 44 bytes
Polje one contains enum (1 byte I guess?), 3 bytes and Bitset with 8 bits (I assume it takes 1 byte + some overhead). That means that total size of data in object is around 5 bytes.
Does that mean that there is 39 bytes of object overhead?
