0

I'm working on a project where i need to plot some data. At the moment i keep all the data in an object and then give the pointer to this object to the graphs. But it is possible to dynamically change the data, whereas i need to change the data the graphs gets. So here is my question:

Should i create a new array every time i edit the data or and then change the pointers in the graphs or should i just change the data within the original array and the just repaint the graphs?

3
  • There's no real need to create a new array if the old one will do, and you no longer need it's prior values. Commented Feb 23, 2013 at 13:32
  • There are no "pointers" in Java. Commented Feb 23, 2013 at 13:33
  • 1
    @LukasKnuth - Yeah, right. Commented Feb 23, 2013 at 13:33

2 Answers 2

1

Using immutable data results in cleaner, more predictable API. If you mutate the array which is currently used by the graph API, nasty interactions are lurking just around the corner. This may lead to the graph API defensively copying the array internally; at that point you lose: you get more copying than you'd needed had you started with an immutable approach up front.

Sign up to request clarification or add additional context in comments.

Comments

1

Keeping one single model is the preferred approach especially from the memory performance point of view. However, it may depend. If you use the same model somewhere else then you must ponder a little bit more.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.