home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / stubshack / HeapGraph_!HeapDisp_c_MoveBlock < prev    next >
Encoding:
Text File  |  1994-11-29  |  1.4 KB  |  67 lines

  1. #include "Shell.Extra.h"
  2. #include "Shell.TextRect.h"
  3.  
  4. #include "Structs.h"
  5. #include "MoveBlock.h"
  6. #include "ChHeapSize.h"
  7. #include "Update.h"
  8.  
  9.  
  10.  
  11. void    MoveBlock( app_block *app, int oldpos, int newpos, int newsize)
  12. {
  13. int    i;
  14.  
  15. /* Find old block    */
  16. for ( i=0; i<app->num_blocks; i++)    {
  17.     if ( app->blocks[i].pos == oldpos)    break;
  18.     }
  19.  
  20. /* i is the old postion of the block    */
  21.  
  22. if ( i<app->num_blocks)    {
  23.  
  24.     int        direction = ( newpos > oldpos ) ? 1 : -1;
  25.     int        j, k, oldsize;
  26.     block_info    tempblock;
  27.  
  28.     oldsize = app->blocks[i].size;
  29.     app->stats.total += newsize - app->blocks[i].size;
  30.  
  31.     tempblock    = app->blocks[i];
  32.     tempblock.pos    = newpos;
  33.     tempblock.size    = newsize;
  34.  
  35.     for ( j=i; j>=0 && j<app->num_blocks; j+=direction)    {
  36.         if ( (app->blocks[j].pos - newpos)*direction > 0)    break;
  37.         }
  38.     j-=direction;
  39.     /* j is now the new postion for the block    */
  40.  
  41.     /* Copy the blocks between old and new postion down/up one step...    */
  42.     for ( k=i; k!=j; k+=direction)
  43.         app->blocks[k] = app->blocks[k+direction];
  44.  
  45.     /* And fill in new block    */
  46.     app->blocks[j] = tempblock;
  47.  
  48.  
  49.     if ( j==0 || j==app->num_blocks-1)    CheckHeapSize( app, newpos, newpos+newsize);
  50.  
  51.     /*Shell_ForceRectUpdateSlow( app->heaprect);*/
  52.     ForceRegionUpdate( app, oldpos, oldsize);
  53.     ForceRegionUpdate( app, newpos, newsize);
  54.  
  55.     }
  56.  
  57. else    Shell_TextRectPrintf( app->textrect,
  58.         "Couldn't find block at 0x%x, (want to realloc to 0x%x, size %i)\n",
  59.         oldpos, newpos, newsize
  60.         );
  61.  
  62. return;
  63. }
  64.  
  65.  
  66.  
  67.