示例#1
0
void *
CrT_malloc(size_t size, const char *file, int line)
{
    Block b = block_find(file, line);

    Header m = malloc(size + CRT_OVERHEAD_BYTES);

    if (!m) {
	fprintf(stderr, "CrT_malloc(): Out of Memory!\n");
	abort();
    }

    m->b = b;
    m->size = size;



#ifdef MALLOC_PROFILING_EXTRA
    /* Look around for trashed ram blocks: */
    CrT_check(file, line);

    /* Remember where end of block is: */
    m->end = &((char *) m)[size + (CRT_OVERHEAD_BYTES - 1)];

    /* Write a sacred value at end of block: */
    *m->end = CRT_MAGIC;

    /* Thread m into linklist of allocated blocks: */
    INSERT(m);

    /* Remember we've touched 'm' recently: */
    just_touched[++next_touched & (CRT_NEW_TO_CHECK - 1)] = m;

#endif


    b->tot_bytes_alloc += size;
    b->tot_allocs_done++;
    b->live_blocks++;
    b->live_bytes += size;

    if (b->live_bytes > b->max_bytes) {
	b->max_bytes = b->live_bytes;
	b->max_bytes_time = time(NULL);
    }
    if (b->live_blocks > b->max_blocks)
	b->max_blocks = b->live_blocks;

    return (void *) (m + 1);
}
示例#2
0
static int does_match(struct node *node, void *data)
{
	struct finddata *finddata = data;
	if ((node->type == AST_IDENTIFIER || node->type == AST_TYPENAME) &&
	    !strcmp(finddata->name->name, node->data)) {
		struct block *block = block_find(finddata->block, node->start);
		struct name *name = block_lookup(block, node);
		if ((!name && extern_node_matches(finddata->name, node)) ||
		    name == finddata->name) {
			struct hit *hit = xmalloc(sizeof(struct hit));
			hit->start = node->start;
			hit->end = node->end;
			hit->cfile = finddata->cfile;
			hit->next = finddata->hit;
			finddata->hit = hit;
		}
	}
	/* don't check nodes outside defining block */
	return 1;
}
示例#3
0
int main(int argc, char *argv[]){
	printf("generating the array...\n");
	/* The following line is used in order to have a sort of random array
	If we comment this line, the array will be the same at every launch of the program*/
	srand((unsigned)time(0));
	
	// the array is allocated and then filled with random floats
	float *p;
	p = malloc(nb*sizeof(float));
	int i;
	
	// Timing
	double t0,t1, t2, t3 ;

	// Filling the array
	for(i=0; i < nb; i++){
		p[i] = ((float)rand()/(float)RAND_MAX)+(rand()%100);
	}
	
	// The value we're looking for
	float val = 0.265625;
	
	printf("Searching with a multithread method...\n");
	t0=now(); i = search_thread(p, nb, val); t1=now(); 
	if(i==0)
		printf("Not found with multithread method\n");
	printf("Multi-Thread T = %6.4f\n",t1-t0);
	
	finished = 0;
	printf("Searching with a monothread method...\n");
	t2 = now(); i = block_find(p, 0, nb-1, val); t3 = now();
	
	if(i==0)
		printf("Not found with mono-thread method\n");
	printf("Mono-Thread T = %6.4f\n",t3-t2);
	
	//Free the memory
	free(p);
}
示例#4
0
/* Thread function 
This is the function that is called when a thread is launched */
void *thread_function(void *threadarg){
 /* Local variables */
  int id;
 /* Shared variables correspondances */
  float *p;
  int i_start, i_end;
  float val;
 /* Association between shared variables and their correspondances */
  struct thread_data *thread_pointer_data;
  thread_pointer_data = (struct thread_data *)threadarg; 
  /* Shared variables */
  id = thread_pointer_data->thread_id;
  p = thread_pointer_data->p;
  i_start = thread_pointer_data->i_start;
  i_end = thread_pointer_data->i_end;
  val = thread_pointer_data->val;
 
  /* Body of the thread */
  rs[id] = block_find(p, i_start, i_end, val);

  pthread_exit(NULL);
  return 0;
}