Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed critics : store objects inside arrays
    primarykey
    data
    text
    <p>In order to improve performance of my java applications, i was thinking about making a class with static final fields that describe an object, and then put static methods that retrieves all the data of the object from an array.</p> <p>example : let's say i want to create an object person: let's say a person has an age, height, weight, color of the eyes, and world coordinates.</p> <p>usually i'd do something like this:</p> <pre><code> public class Person { private int age; private int height; private int weight; private int eyeR; private int eyeG; private int eyeB; private float x; private float y; private float z; //... getters and setters } </code></pre> <p>I want to send the persons from a client to a server, so i have to serialize the objects and send them to the server wich will deserialize the object and resurrect the person on the other side, now we all know that java objects are stored in the heap and that every object have a minimum of bytes that are allocated to describe the object.</p> <p>What I wanna do is this instead : make a a class that describes an object person :</p> <pre><code>public class Person { // size contains the number of bytes to describe my person public static final int size; //this byte here is used to identify a Person in a float array public static byte classID = 0; //these variables contains the position of my attributes inside a float array // since floats / int are all coded in 4 bytes public static final int age = 0; public static final int height = 1; public static final int eyeR = 2; public static final int eyeG = 3; public static final int eyeB = 4; public static final int x = 5; public static final int y = 6; public static final int z = 7; //i don't check for nullity, i trust myself. public static int getAge(final float[] person) { return person[Person.age]; } public static void setAge(final float[] person, float age) { return person[Person.age] = age; } ... do the same thing for the rest also you can store </code></pre> <p>}</p> <p>I'd really like to know if this solution is viable, because since i am using only float arrays to store my person data, i can get spatial proximity of my data in the memory, so i guess if I access the data i wont make any page misses.</p> <p>also i wont have to serialize or deserialize my objects, because my float array is good as is, i'll just use my static methods to access my float array.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload