home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / clibs / HeapGraph / !HeapDisp / c / MoveBlock < prev    next >
Encoding:
Text File  |  1994-09-01  |  1.2 KB  |  62 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.  
  8.  
  9.  
  10. void    MoveBlock( app_block *app, int oldpos, int newpos, int newsize)
  11. {
  12. int    i;
  13.  
  14. /* Find old block    */
  15. for ( i=0; i<app->num_blocks; i++)    {
  16.     if ( app->blocks[i].pos == oldpos)    break;
  17.     }
  18.  
  19. /* i is the old postion of the block    */
  20.  
  21. if ( i<app->num_blocks)    {
  22.  
  23.     int        direction = ( newpos > oldpos ) ? 1 : -1;
  24.     int        j, k;
  25.     block_info    tempblock;
  26.  
  27.     app->stats.total += newsize - app->blocks[i].size;
  28.  
  29.     tempblock    = app->blocks[i];
  30.     tempblock.pos    = newpos;
  31.     tempblock.size    = newsize;
  32.  
  33.     for ( j=i; j>=0 && j<app->num_blocks; j+=direction)    {
  34.         if ( (app->blocks[j].pos - newpos)*direction > 0)    break;
  35.         }
  36.     j-=direction;
  37.     /* j is now the new postion for the block    */
  38.  
  39.     /* Copy the blocks between old and new postion down/up one step...    */
  40.     for ( k=i; k!=j; k+=direction)
  41.         app->blocks[k] = app->blocks[k+direction];
  42.  
  43.     /* And fill in new block    */
  44.     app->blocks[j] = tempblock;
  45.  
  46.  
  47.     if ( j==0 || j==app->num_blocks-1)    CheckHeapSize( app, newpos, newpos+newsize);
  48.  
  49.     Shell_ForceRectUpdateSlow( app->heaprect);
  50.     }
  51.  
  52. else    Shell_TextRectPrintf( app->textrect,
  53.         "Couldn't find block at 0x%x, (want to realloc to 0x%x, size %i)\n",
  54.         oldpos, newpos, newsize
  55.         );
  56.  
  57. return;
  58. }
  59.  
  60.  
  61.  
  62.