home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / clibs / HeapGraph / !HeapDisp / c / AddBlock next >
Encoding:
Text File  |  1994-09-02  |  1.5 KB  |  73 lines

  1. #include "AddBlock.h"
  2. #include "Shell.Extra.h"
  3. #include "Shell.Printf.h"
  4.  
  5. #include "ChHeapSize.h"
  6. #include "Shell.SafeAlloc.h"
  7.  
  8. #define BLOCK_INCREMENT 16
  9.  
  10.  
  11.  
  12. void    AddBlock( app_block *app, int pos, int size, int ref)
  13. {
  14. block_info    *block;
  15. int        i, j;
  16.  
  17. if (size<0)    {
  18.     Shell_TextRectPrintf( app->textrect, "Negative block size at %x, (size=%i)\n", pos, size);
  19.     return;
  20.     }
  21.  
  22. if ( app->num_blocks == app->num_blocksalloced)    {
  23.     app->num_blocksalloced += BLOCK_INCREMENT;
  24.     app->blocks = Shell_SafeRealloc(
  25.         app->blocks, app->num_blocksalloced*sizeof( block_info)
  26.         );
  27.     }
  28.  
  29. /* Find where to place the block    */
  30.  
  31.  
  32. for ( i=0; i<app->num_blocks; i++)    {
  33.     if ( app->blocks[i].pos > pos)    break;
  34.     }
  35.  
  36. /* copy blocks up...    */
  37. for ( j=app->num_blocks; j>i; j--)    app->blocks[j] = app->blocks[j-1];
  38.  
  39. block = &app->blocks[ i];
  40.  
  41. block->pos    = pos;
  42. block->size    = size;
  43. block->ref    = ref;
  44.  
  45. app->num_blocks++;
  46. app->stats.total += size;
  47. /*
  48. Shell_Printf( "Blocks are:\n");
  49. for ( i=0; i<app->num_blocks; i++)    {
  50.     Shell_Printf( "%i) %x\n", i, app->blocks[i].pos);
  51.     }
  52. Shell_Printf( "\n");
  53. */
  54.  
  55. /*Shell_Printf( "%x\n", pos);*/
  56.  
  57. CheckHeapSize( app, pos, pos+size);
  58.  
  59. Shell_ForceRectUpdateSlow( app->heaprect);
  60.  
  61.     /* Should only update the new bit of the heap...    */
  62.     /*
  63.     {
  64.     wimp_rect    rect;
  65.     rect.min.x = app->heapdisplay->rect.min.x;
  66.     rect.max.x = app->heapdisplay->rect.max.x;
  67.     rect.min.y = app->heapdisplay->rect.min.y + pos/app->words_per_os;
  68.     rect.max.y = app->heapdisplay->rect.min.y + (pos+size)/app->words_per_os;
  69.     }
  70.     */
  71.  
  72. }
  73.