Memory model in a Javacard.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Virat_Bhartiya
Posted On:   Wednesday, January 9, 2002 02:56 AM

I have been trying to understand the memory model of the javacard for sometime and I must confess that I am still confused. Firstly - at more places than one,I have read that if one allocates memory using a new operator - the memory remains allocated for the life time of the card. Is this true in all cases? Case 1: the memory is allocated to a member variable of the applet inside a function called from process().(this means that the function is called a number of times) Case 2: the memory is allocated to a local variable inside a function called from process(). Case 3: the memory is allocated to a member variable inside the constructor of the applet. I have writ   More>>

I have been trying to understand the memory model of the javacard for sometime and I must confess that I am still confused.

Firstly - at more places than one,I have read that if one allocates memory using a new operator - the memory remains allocated for the life time of the card. Is this true in all cases?



Case 1: the memory is allocated to a member variable of the applet inside a function called from process().(this means that the function is called a number of times)



Case 2: the memory is allocated to a local variable inside a function called from process().



Case 3: the memory is allocated to a member variable inside the constructor of the applet.



I have written a number of applets and loaded them into the card using a loader. The loader has the ability to display the free EEPROM space remaining in the card at any time. Following have
been my observations:



case 1: Memory is consumed only once - when the function is called for the first time. On subsequent execution of the same function the memory is not eaten up.



case 2: I allocated 256 bytes but the memory was never consumed - not even once - on the execution of the function.




case 3: the memory was consumed only once obviously - during the installation of the applet. No problems in this case.



Please let me know why the memory is consumed only once in case1 and never in case2.

   <<Less

Re: Memory model in a Javacard.

Posted By:   Julien_SIMON  
Posted On:   Thursday, January 10, 2002 12:39 AM

Hi Virat,



I'm assuming you're talking about persistent data, not transient data.



As of Java Card 2.1.1, the standard doesn't provide garbage collection. So, EEPROM allocated using new will remained allocated "forever". This also means that when an object becomes unreferenced, its memory is lost "forever".



However, some platforms do provide proprietary GC, and it looks like JC 2.2 will feature GC as well.





Regarding your cases, I have no problem with case 3: this is indeed how it must work. The other two cases are not what I expected... I don't know what Java Card platform you're working on, but I would be really surprised it if failed to comply to the memory model ! Are you sure the amount of free EEPROM returned by the loader is really a dynamic value, i.e. is it really updated after each new ? Or does it just reflect the amount of EEPROM available to load other applets, in which case it wouldn't change ?



In any case, feel free to send me your code if you have any doubts.

About | Sitemap | Contact