Given two solutions: 1.==================================================== class A { final int b; final C e; class C { final int D() { return b; } }; void create() { e = C(); }; };
or 2.: ================================================
class C { final array b; final array D() { return b; }; void create(array _b) { b = _b; }; };
class A { final array b; final C e; void create() { e = C(b); }; }; ====================================================
Assuming that there are (a lot) more other members and methods in both classes (which are accessed within the class, not cross-class), and further assuming that the A class is being instantiated a *lot*: What would the runtime impact of these two approaches considering CPU time and memory used?
I would guess that solution 1 would be slightly more efficient, both memory and CPU-wise. Or am I overlooking something here where due to the nested stack frames of solution 1, the actual CPU or memory usage is higher than expected?
Given two solutions:
[...]
Assuming that there are (a lot) more other members and methods in both classes (which are accessed within the class, not cross-class), and further assuming that the A class is being instantiated a *lot*: What would the runtime impact of these two approaches considering CPU time and memory used?
I would guess that solution 1 would be slightly more efficient, both memory and CPU-wise.
Correct; in solution 2 class A will need the parent pointer to resolve C at runtime.
Or am I overlooking something here where due to the nested stack frames of solution 1, the actual CPU or memory usage is higher than expected?
Doubtful.
/grubba
Or just class C(array b) { ... } and remove create() completely, though I haven't checked if the final modifier can be combined with that syntax.
pike-devel@lists.lysator.liu.se