Ejemplo n.º 1
0
int FName::NameManager::FindName (const char *text, bool noCreate)
{
	if (!Inited)
	{
		InitBuckets ();
	}

	if (text == NULL)
	{
		return 0;
	}

	unsigned int hash = MakeKey (text);
	unsigned int bucket = hash % HASH_SIZE;
	int scanner = Buckets[bucket];

	// See if the name already exists.
	while (scanner >= 0)
	{
		if (NameArray[scanner].Hash == hash && stricmp (NameArray[scanner].Text, text) == 0)
		{
			return scanner;
		}
		scanner = NameArray[scanner].NextHash;
	}

	// If we get here, then the name does not exist.
	if (noCreate)
	{
		return 0;
	}

	return AddName (text, hash, bucket);
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: bochf/testing
/* ========================================================================= */
int main(int argc, char *argv[])
{
   struct options *o;

   /* API data */
   ipcinfo_shm_t *shmbuf = NULL;
   int size;
   char fact_string[32];

   /* Result data */
   long count = 0;
   int no_attach_cnt = 0;
   size64_t total_size = 0;
   size64_t min_size = 0;
   size64_t max_size = 0;
   struct per_user *ulist = NULL;
   struct barray *ba = NULL;

   /* General usage */
   int i;
   int keep_trying;



   if ( NULL == (o = ReadOptions(argc, argv)) )
      return(1);

   if ( o->bError )
      return(1);

   if ( o->bAbout )
      return(about());

   if ( o->bHelp )
      return(help());

   keep_trying = 1;
   while ( keep_trying )
   {
      if ( shmbuf )
         free(shmbuf);

      /*** Determine size of required buffer ***/
      if ( ENOSPC != get_ipc_info(0,
                                  GET_IPCINFO_SHM_ALL,
                                  IPCINFO_SHM_VERSION_1,
                                  NULL,
                                  &size))
      {
         fprintf(stderr, "ERROR: Unable to determine size/count of data.\n");
         return(1);
      }

      /*** Allocate memory for the buffer/array */
      if ( NULL == (shmbuf = (ipcinfo_shm_t *)malloc(size)) )
      {
         fprintf(stderr, "ERROR: Failed to allocate memory.\n");
         return(1);
      }
      
      /* Copy in the data to the allocated array ***/
      switch (  get_ipc_info(0,
                         GET_IPCINFO_SHM_ALL,
                         IPCINFO_SHM_VERSION_1,
                         (char *)shmbuf,
                         &size) )
      {
      case 0:
         keep_trying = 0;
         break;
      case ENOSPC:
         break;
      default:
         fprintf(stderr, "ERROR: Problems retrieving IPC data.\n");
         return(1);
         /* Unreachable */
         break;
      }
   }

   /* Determine count from size */
   count = size / (int)(sizeof(ipcinfo_shm_t));

   if ( o->bSizeGph )
   {
      ba = InitBuckets(BA_BASE10);
   }


   /*** Walk through the array deriving results as we go ***/
   i = 0;
   while ( i < count )
   {
      if ( shmbuf[i].shm_nattch = 0 )
         no_attach_cnt++;

      total_size += shmbuf[i].shm_segsz;

      if ( i == 0 )
      {
         min_size = shmbuf[i].shm_segsz;
         min_size = shmbuf[i].shm_segsz;
      }

      if ( min_size > shmbuf[i].shm_segsz )
          min_size = shmbuf[i].shm_segsz;

      if ( max_size < shmbuf[i].shm_segsz )
          max_size = shmbuf[i].shm_segsz;


      if ( o->bSizeGph )
         BucketValue(ba, shmbuf[i].shm_segsz);

      if ( o->bPerUser )
         ulist = collect_per_user(ulist, &shmbuf[i]);

      i++;
   }

   /*** Display results ***/
   printf("Number of shm segments               : %d\n", count);
   printf("Number of no-attach segments         : %d\n", no_attach_cnt);
   factor_bytes(fact_string, total_size);
   printf("Total size of shm segments (human)   : %s\n", fact_string);
   printf("Total size of shm segments (bytes)   : %llu\n", total_size);
   factor_bytes(fact_string, max_size);
   printf("Maximum sized shm segment            : %s\n", fact_string);
   factor_bytes(fact_string, min_size);
   printf("Minimum sized shm segment            : %s\n", fact_string);


   if ( ulist )
      dump_ulist(ulist);

   if ( ba )
   {
      int max_count;

      max_count = GetMaxCount(ba);

      printf("Size distribution data:\n");
      DumpBucketArray(ba, max_count);
   }
   fflush(stdout);

   return(0);
}
Ejemplo n.º 3
0
	void CollisionSystem::Update()
	{
		InitBuckets();
		ResolveCollisions();
	}