efficient referencing between classes

edited December 2016 in Programming Questions

Hello, Ive been working on a sketch for a while now, tragically without a clear plan from the start.

Naturally everything is becoming messy now and out of hand.

I have 4 classes/objects, interface, grids, matchBox, control.

interface contains an arrayList of grids objects, matchBox contains a fixed size array of control objects, each control object in the array needs info on some, but not all of the parameters of the grids arrayList objects..

My question is, is it more efficient to make IntLists (they can vary in size) of the specific grids properties, and pass them on to the control objects via matchBox, or is it better(more cpu efficient) to send the whole grids arrayList to matchBox then to each control?

Answers

  • DO NOT name a class as "interface". It is a keyword in Java.

  • As to the question, I doubt if the impact would be noticeable whatever you choose.
    Since the second option is simple, why not just use it.

  • edited December 2016

    ah thanks, good to know. i made up those names to simplify my post, I am using different unique names in the actual sketch.

    I have to loop through all the mentioned arrays quite a lot and I was worried that the impact would become noticeable, but if you think it won't make much difference I would happily just pass the whole arrayList on.

    Regarding passing on the arrayList, is there a big difference if you make a function in each class to handle/pass on the data, or is it just as cpu intensive to do something like

    matchBox.control.newGrids = grids; //where newGrids is placeholder arrayList in control

  • I don't understand, do you mean I shouldn't be using classes at all?

  • I believe that he means to say that you should just stick to one single ArrayList.

  • edited December 2016

    I think I can see what you mean, my feeling is that I need to start again from the ground up and plan a new structure.

    I don't know how I will do it, yet, since there are many functions which depend on/manipulate arrays derived from other functions.

    I tried to use classes where I knew I would need an array of items with their own specific properties, but inevitably they were all going to start depending on each other in overlapping fashion and make a web of confusion for me..

  • @GoToLoop Just asking, but is t that example you gave for p5.js?

  • edited December 2016

    There are versions for both p5.js & Pjs libraries there. ;;)
    However, the Pjs 1s are using some bastardized mix of Java & JS syntaxes. :-&
    Therefore those only work for the web, not in Java Mode! ~O)

  • I'm using processing/ just java, afaik that thread is about 2d array iteration with one or two properties, relevance? i also have no idea what your code is doing in any of those posts.

    I've made loads of different automata sketches in the past with no issues. My question here is about how to organise a sketch in the aforementioned specific situation.

    Anyway I get the general message, I need to be more clever and read up more on how to structure my sketches, only post in forum with more specific/ concrete query

  • My examples there create some fixed-size array and initialize it sequentially upfront, so any objects created are laid out near each other.

    This way, when in draw(), and the loop iterates over it, the chances are gr8 the whole reading will be CPU-pipelined in its caches. \m/

  • As I said, I don't understand your code. Could you give a java example, with formal beginner friendly syntax? Or just elaborate further on what you are saying. No worries if not, I'm on a long bus trip and won't be able to work on the sketch for a while.

  • You know, the best way would be to just try out both methods and check which is better. I doubt if it even matters much in your case, unless you either have a very resource intensive program or have a slow processor, or are actually aiming to make a very lightweight program that can run in background.

Sign In or Register to comment.