Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return a slice in Java

I am working on a JavaCard, so a SIM card that runs Java (or a subset of it: Java Embedded). Due to memory limitations I have an array that I reuse for multiple tasks.

I want a function to basically return a pointer to that array, with an offset, thus a slice. This way I can be sure that no part of that array will be overwritten by accident.

Pointers dont exactly exist in Java, but is there a way to return a part of an array without copying it?

like image 251
Typhaon Avatar asked Oct 15 '25 00:10

Typhaon


1 Answers

No, this is not possible. Object (references) is the closest you can get to pointers in Java.

If this were regular Java, I would have suggested, to wrap the array in a List with Arrays.asList and then use the List method subList, which provides a view of a section of the list without copying its contents.

However If I read the JavaCard API reference correctly these aren't included. You could try write a simple version of those interfaces/classes/methods yourself.

like image 158
RoToRa Avatar answered Oct 17 '25 14:10

RoToRa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!