Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Applet's own space

JavaCard Applet Development Related Questions and Answers.
hanjing
Posts: 2
Joined: Wed Aug 31, 2016 9:58 pm
Points :42
Contact:

Applet's own space

Post by hanjing » Thu Jun 14, 2018 10:01 pm

This problem may be a little strange, but it is indeed an application developer proposed to me.
How can an Applet know how much NVM space it occupies?
I don't want to use JCSystem.getAvailableMemory() to achieve this because its return value is too small, but my card space can be quite large.

wumindejia
Posts: 55
Joined: Thu Sep 22, 2016 5:05 am
Points :784
Contact:

Re: Applet's own space

Post by wumindejia » Fri Jun 15, 2018 4:27 am

You can keep new space until SystemException.NO_RESOURCE == ex.getReason()

scplatform
Posts: 39
Joined: Wed Aug 31, 2016 9:55 pm
Points :372
Contact:

Re: Applet's own space

Post by scplatform » Fri Jun 15, 2018 4:50 am

Maybe you can do it like this:

Code: Select all

byte[] buf = apdu.getBuffer();
      byte p1 = buf[ISO7816.OFFSET_P1];
      switch (buf[ISO7816.OFFSET_INS]) {
      case (byte) 0x00:
         byte type=0;
         if(0==p1)
            type=JCSystem.MEMORY_TYPE_PERSISTENT;
         else if(1==p1)
            type=JCSystem.MEMORY_TYPE_TRANSIENT_RESET;
         else if(2==p1)
            type=JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT;
         else
            ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
         
         memsize=JCSystem.getAvailableMemory(type);
         allmemsize=memsize;
         while(memsize==(short)32767){
            if(type==JCSystem.MEMORY_TYPE_PERSISTENT)
               bbb=new byte[memsize];
            else
               bbb=JCSystem.makeTransientByteArray(memsize,type);
            memsize=JCSystem.getAvailableMemory(type);
            allmemsize+=memsize;
         }
         bbb=null;
         JCSystem.requestObjectDeletion();
         buf[3]=(byte)(allmemsize);
         buf[2]=(byte)(allmemsize>>8);
         buf[1]=(byte)(allmemsize>>16);
         buf[0]=(byte)(allmemsize>>24);
         //buf[1]=(byte)(memsize>>8);
         apdu.setOutgoingAndSend((short)0, (short)4);
         break;
      default:
         // good practice: If you don't know the INStruction, say so:
         ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
      }

later123654
Posts: 11
Joined: Tue May 22, 2018 9:43 pm
Points :130
Contact:

Re: Applet's own space

Post by later123654 » Fri Jun 15, 2018 5:05 am

you can use a new API(since jck3.0.4) to get the size:

public static void getAvailableMemory(short[] buffer,
short offset,
byte memoryType)
throws SystemException

Obtains the amount of memory of the specified type that is available to the applet. Note that implementation-dependent memory overhead structures may also use the same memory pool. The requested memory information is returned as a 32 bit number stored in the specified short array - buffer. The 32 bit number number is the concatenation of buffer[offset] and buffer[offset+1].
Notes:
•The number of bytes returned is only an upper bound on the amount of memory available due to overhead requirements.
•Allocation of CLEAR_ON_RESET transient objects may affect the amount of CLEAR_ON_DESELECT transient memory available.
•Allocation of CLEAR_ON_DESELECT transient objects may affect the amount of CLEAR_ON_RESET transient memory available.
•The 32 bit number is not an indicator of the size of object which may be created since memory fragmentation is possible.
Parameters:memoryType - the type of memory being queried. One of the MEMORY_TYPE_* constants defined above, for example MEMORY_TYPE_PERSISTENT.buffer - the output buffer for storing memory size informationoffset - the offset within the buffer where memory size information beginsThrows:ArrayIndexOutOfBoundsException - if buffer[offset] or buffer[offset+1] outside array boundsNullPointerException - if buffer is nullSystemException - with the following reason codes: •SystemException.ILLEGAL_VALUE if memoryType is not a valid memory type.
Since:3.0.4

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 24 guests

JavaCard OS : Disclaimer