コード例 #1
0
ファイル: heap.c プロジェクト: jasondegraw/View3D
void MemRem(I1 *msg)
{
#if( __TURBOC__ >= 0x295 )
  struct heapinfo hp;   // heap information
  U4 bytes = coreleft();
  fprintf(_ulog, "%s:\n", msg);
  fprintf(_ulog, "  Unallocated heap memory:  %ld bytes\n", bytes);

# if( MEMTEST > 1 )
  switch(heapcheck()) {
  case _HEAPEMPTY:
    fprintf(_ulog, "The heap is empty.\n");
    break;
  case _HEAPOK:
    fprintf(_ulog, "The heap is O.K.\n");
    break;
  case _HEAPCORRUPT:
    fprintf(_ulog, "The heap is corrupted.\n");
    break;
  }  // end switch

  fprintf(_ulog, "Heap: loc, size, used?\n");
  hp.ptr = NULL;
  while(heapwalk(&hp) == _HEAPOK) {
    fprintf(_ulog, "[%p]%8lu %s\n",
            hp.ptr, hp.size, hp.in_use ? "used" : "free");
  }
# endif
}
コード例 #2
0
ファイル: heapwalk.c プロジェクト: xuwenbo/KR
int
main(void)
{
    struct tag_heap *pcurrentheap = NULL;
    char sztext[]                 = "Walking heap\r\n";
    size_t len                    = 0;
    char *psz                     = NULL;

    len = strlen(sztext);

    psz = (char *)malloc(len + 1);
    if (NULL == psz)
    {
        goto ERROR_PROCESS;
    }
    else
    {
        strcpy(psz, sztext);
    }

    heapwalk((struct tag_heap *)((int)psz - OFFSET));

ERROR_PROCESS:
    if (psz)
    {
        free(psz);
        psz = NULL;
    }

    return 0;
}
コード例 #3
0
ファイル: JPUSHPOP.C プロジェクト: mrchurrisky/chaos
static void heapwalker(void)
{
	struct heapinfo hi;

	hi.ptr = NULL;
	while (heapwalk(&hi) == _HEAPOK)
		putz++;
}
コード例 #4
0
ファイル: OLDALLOC.C プロジェクト: jeske/GTalk
void grab_all_available_memory(int use_ems)
{/*
  unsigned long int precore = coreleft();
  */
  unsigned long int precore = 400000;
  unsigned long int core_left = precore /* - DAVE_FUDGE_FACTOR */;
  unsigned long int bytes = (unsigned int) (core_left);
  void *total_memory_pointer;


#ifdef MEM_DEBUG
  int result=0;
  struct heapinfo test;
/*	unsigned *_seg; */

  printf("Found: %lu\n",precore);
#endif

#ifdef MEM_DEBUG
  test.ptr=NULL;
  do
   {
	 result=heapwalk(&test);
	 printf("FarHeapSize %lu  Used: %d Ptr:%lX Res:%d\n",test.size,test.in_use,test.ptr,result);
   } while ((result!=5) && (result!=1));
   printf("Result: %d\n",result);

/*	printf("Total Memory (_dos_allocmem) Rtn: %u  SegPtr: %u\n",_dos_allocmem(0xFFFFu,_seg),(unsigned int)*_seg); */
#endif

/*	total_memory_pointer = malloc((unsigned long int)core_left); */

  DosAllocMem(&total_memory_pointer,core_left,PAG_READ | PAG_WRITE | PAG_COMMIT);

/* (char *)*total_memory_pointer=0; */

  printf("Allocated memory starting at %p\n",total_memory_pointer);

#ifdef MEM_DEBUG
  printf("Allocated: %lX\n",total_memory_pointer);

  test.ptr=NULL;
  do
   {
	 result=heapwalk(&test);
	 printf("FarHeapSize %lu  Used: %d Ptr:%lX Res:%d\n",test.size,test.in_use,test.ptr,result);
   } while ((result!=5) && (result!=1));
   printf("Result: %d\n",result);
#endif

  if (!total_memory_pointer)
  {
	printf("Could not allocate memory!\n");
	g_exit(1);
  }
  if (!tasking)
	{
	 printf("CoreLeft Begin: %ld asking for %ld \n",precore,core_left);
	 printf("We have [%ud] bytes\n",bytes);
	}
  mem_handles = 0;
  insert_memory_entry_at(0,(char *)total_memory_pointer,
					  -1,bytes,1,"EMPTY",1);

  sys_toggles.total_starting_memory=core_left;
/*	sys_toggles.total_dos_starting_memory=coreleft(); */


  use_ems=0;

#ifdef MEM_DEBUG
  g_exit(1);
#endif
}