Reputation: 603
I wonder if anyone knows exactly where is temp
array stored (EEPROM or RAM) in the following Java Card method (part of source code of WalletDemoApplet I have found inside JCIDE samples directory) . Please note that the array is not allocated by means of makeTransientByteArray. Also it is declared as a local variable inside a method.
private void calIntegral(byte [] buf,byte soff,short len)
{
byte temp[]={0x00,0x00,0x00,0x00};
short low=0;
byte aa=0;
if (len==2)
Util.arrayCopy(buf, soff, temp,(short)2, len);
else
Util.arrayCopy(buf, soff, temp,(short)0, len);
...
}
Also, in the Java Card Applet Developer's Guide, you can find:
The Converter ensures that memory is allocated for the contents of static fields, namely, primitive data types and references to arrays. Memory is allocated for instances by using the new bytecode from the system heap and cannot be reclaimed (unless the smart card implements a garbage collector). Memory for method variables, locals, and parameters is allocated from the stack and is reclaimed when the method returns.
Upvotes: 2
Views: 935
Reputation: 41
Any Array will be created in EEPROM
, that is not created with makeTransientByteArray
. You can check available and consumed memory in JCIDE
tool.
In this example memory will be assign again and again in EEPROM
, when this methods will be called.
Upvotes: 0
Reputation: 94058
This part of the WalletDemoApplet
should certainly not be generated in a local variable:
byte temp[]={0x00,0x00,0x00,0x00};
That's EEPROM storage; the new byte[]
part may be hidden, but the array creation is still performed, as specified by the JLS:
An array initializer creates an array and provides initial values for all its components.
here the array initializer is the braces and anything within it.
Please ignore at least that part of the example. Generally you would use a static method for that, and using a class field with makeTransientByteArray
(called during instantiation of the Applet) as buffer. That is: if you require an array, simply defining 4 byte variables or - in this case - directly setting byte values could work as well.
Upvotes: 4