home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / code / stubshack / HeapGraph / !HeapDisp / c / AddBlock next >
Encoding:
Text File  |  1994-11-29  |  1.6 KB  |  81 lines

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