4 ms·
>High-performance Java is indeed basically writing C in Java, including using you own byte array for memory. Oh, I wish. For example, in C you can easily retur
by noctune 5y ago
>High-performance Java is indeed basically writing C in Java, including using you own byte array for memory.
Oh, I wish. For example, in C you can easily return multiple values through pointers. In Java, you have no such luxury without allocating so it's even less flexible if you can't allocate.
- kaba0 5y agoI’m not sure what you have in mind but returning pointer to a value on the stack may very well be a huge error.
- tempodox 5y agoOf course it's a huge error, which is why you should never do that. Instead, you pass the addresses of local stack variables to that function as pointer arguments and let that function write its outputs there. Voilà, multiple return values without heap allocations.
- kaba0 5y agoOr you pass `this` and set a field of that in a function, which is equivalent.
- AmpsterMan 5y agoThat's a bit of a stretch using the word 'return' there. Forgive my exactness, but return implies, well, returning a value from a function. I'd say that Java has similar semantics to C. One can easily pass object references to a function that sets their data. That looks and behaves almost exactly like C. The fact that the references are allocated on the heap is an implementation detail. Let me be clear, a pointer to a struct on the stack in C is obviously not the same as a reference to an object allocated on the heap in Java. The point is that from the point of view of what the language induces you to do, Java and C are similar. Anyone that has used older libraries in Java can attest to this; they look and feel remarkably like C.
- guavaNinja 5y agoI think they meant you allocate data once and pass their pointers to a function to put its outputs there. `void return_multi(T* out0, M*out1);`
- kaba0 5y agoBut then you can just pass in a mutable object as well in java.