Post Reply 
[HP48] Memory Management
10-27-2014, 12:04 PM
Post: #6
RE: [HP48] Memory Management
(10-27-2014 10:12 AM)Bruno Wrote:  I can summarize your method in these few steps:
  1. Move destination object 'A' at the end (in memory) of the current directory.
Make that the "beginning" of the directory. Remember that UserOB is at the end of the memory and grows down. STO adds objects at the beginning (that's why my example added EXTRA as the first variable in the dir) to move less memory, and so should you.
(10-27-2014 10:12 AM)Bruno Wrote:  
  • Create EXTRA variable of size: (object to insert in 'A') - (2.5 bytes of 'A' offset field) - ('EXTRA' Name Length) - (2*1 bytes of EXTRA name length fields)
    • Q -> Why the HP48 need the name length field to be present before AND after the name field ???
    • This is also true for Backup and Library objects. Curious...
Because sometimes it needs to skip the object backwards. If you know the object and want to know the name of the variable, you simply take the pointer of the object, read the length of the name which is stored 2 nibbles before, and from then you can skip the text and get a pointer to the prolog of the name, without scanning through the whole directory.

(10-27-2014 10:12 AM)Bruno Wrote:  
  • (3 or 4?)- Now 'EXTRA' is after 'A' in memory, and is the last variable of the current directory.
    • So, we need to update the last RRP's offset field (after 'EXTRA' variable) to skip 'EXTRA' and point directly to 'A'
    • Thus, 'A' became again the last variable of the current directory. 'EXTRA' becoming a ghost variable.
  • (4 or 3?)- Expand 'A' to "engluf" 'EXTRA' and insert the new object in 'A'
  • That's All ?

    That's all. It's not difficult at all. The trick is to sort the variables properly to assure that EXTRA is after A (it seems to be your preferred way, in my example I put it before for performance reasons, so you only move memory within the object, otherwise you have to sort the variables first, moving everything in userOB which can be slow).
    You can use sysRPL or even the userRPL commands to STO and sort the variables, then RCL 'A' to the stack (to get a pointer) and 'EXTRA' as well. With a little ASM, just do a SKIPOB over EXTRA to get a pointer to the end of it, add 5 to the A pointer to get the size field address, and the difference between the pointers should be stored right there as the new size. The main thing is don't mess up the new size calculation, other than that it's relatively safe as long as you sort the variables properly.
    If you don't, your 'A' will "engulf" any other variables that are between 'A' and 'EXTRA'. And if EXTRA is before A, your size will become negative... causing a system crash, and almost surely a memory clear. But you can detect this condition in you ASM and refuse to do it.

    Claudio
    Find all posts by this user
    Quote this message in a reply
    Post Reply 


    Messages In This Thread
    [HP48] Memory Management - Bruno - 10-24-2014, 12:34 PM
    RE: [HP48] Memory Management - Claudio L. - 10-24-2014, 04:48 PM
    RE: [HP48] Memory Management - Bruno - 10-27-2014, 10:12 AM
    RE: [HP48] Memory Management - Claudio L. - 10-27-2014 12:04 PM
    RE: [HP48] Memory Management - Paul Dale - 10-27-2014, 10:18 AM
    RE: [HP48] Memory Management - Bruno - 10-27-2014, 01:15 PM
    RE: [HP48] Memory Management - Han - 10-27-2014, 10:08 PM
    RE: [HP48] Memory Management - Bruno - 10-29-2014, 10:15 PM



    User(s) browsing this thread: 1 Guest(s)