Ejemplo n.º 1
0
int main()
{
  heap H = heap_new(7, &higher_priority);
  int *a = malloc(sizeof(int));
  int *b = malloc(sizeof(int));
  int *c = malloc(sizeof(int));
  int *d = malloc(sizeof(int));
  int *e = malloc(sizeof(int));
  int *f = malloc(sizeof(int));
  int *g = malloc(sizeof(int));
  *a = 2;
  *b = 6;
  *c = 9;
  *d = 10;
  *e = 8;
  *f = 15;
  *g = 11;
  heap_add(H, (void*)a);
  heap_add(H, (void*)b);
  heap_add(H, (void*)c);
  heap_add(H, (void*)d);
  heap_add(H, (void*)e);
  heap_add(H, (void*)f);
  heap_add(H, (void*)g);

  heap_rem_elem(H, (void*)b);
  print_heap(H);
  heap_rem_elem(H, (void*)e);
  print_heap(H);

  free_heap(H);
  return 0;
}
Ejemplo n.º 2
0
BpMemoryHeap::~BpMemoryHeap() {
    if (mHeapId != -1) {
        close(mHeapId);
        if (mRealHeap) {
            // by construction we're the last one
            if (mBase != MAP_FAILED) {
                sp<IBinder> binder = const_cast<BpMemoryHeap*>(this)->asBinder();

                if (VERBOSE) {
                    ALOGD("UNMAPPING binder=%p, heap=%p, size=%d, fd=%d",
                            binder.get(), this, mSize, mHeapId);
                    CallStack stack;
                    stack.update();
                    stack.dump("callstack");
                }

                munmap(mBase, mSize);
            }
        } else {
            // remove from list only if it was mapped before
            sp<IBinder> binder = const_cast<BpMemoryHeap*>(this)->asBinder();
            free_heap(binder);
        }
    }
}
Ejemplo n.º 3
0
Archivo: gc.c Proyecto: Everysick/mruby
void
mrb_gc_destroy(mrb_state *mrb, mrb_gc *gc)
{
  free_heap(mrb, gc);
#ifndef MRB_GC_FIXED_ARENA
  mrb_free(mrb, gc->arena);
#endif
}
Ejemplo n.º 4
0
void main(void) {
    HardwareInit();
    UartInit(STDIO,115200,DEFAULT_LINE_CTRL);
    heap_size=free_heap();
#if defined DEBUG
    test_pattern();
#endif
    UartPrint(STDOUT,"video initialization\r");
    VideoInit();
    delay_ms(500);
    UartPrint(STDOUT,"keyboard initialization: ");
    if (KeyboardInit()){
        UartPrint(STDOUT,"OK\r");
        comm_channel=LOCAL_CON;
    }else{
        UartPrint(STDOUT,"keyboard error\r");
        UartPrint(STDOUT,"Using uart2 channel.\r");
        comm_channel=SERIAL_CON;
    }
    text_coord_t cpos;
    UartPrint(STDOUT,"SD initialization: ");
    if (!mount(0)){
        UartPrint(STDOUT,"Failed\r");
        SDCardReady=FALSE;
    }else{
        UartPrint(STDOUT,"succeeded\r");
        SDCardReady=TRUE;
    }
    UartPrint(STDOUT,"SRAM initialization\r");
    sram_init();
    UartPrint(STDOUT,"sound initialization.\r");
    tune((unsigned int*)&e3k[0]);
    UartPrint(STDOUT,"initialization completed.\r");
    set_cursor(CR_BLOCK); // sauvegare video_buffer dans SRAM
    clear_screen();
#if defined _DEBUG_
    graphics_test();
    set_curpos(0,LINE_PER_SCREEN-1);
    print(comm_channel,"test");
    sram_write_block(100000,video_bmp,BMP_SIZE);
    delay_ms(1000);
    clear_screen();
    delay_ms(1000);
    sram_read_block(100000,video_bmp,BMP_SIZE);
    delay_ms(1000);
    clear_screen();
//    print(comm_channel,"heap_size: ");
//    print_int(comm_channel,heap_size,0);
//    crlf();
#endif
    shell();
} // main()
Ejemplo n.º 5
0
void Naive_Estimator_Destroy(Naive_Estimator_type * est)
{
  prng_Destroy(est->prng);
  for(int i=0; i < est->c; i++)
  {
    Naive_Sample_Destroy(est->samplers[i]);
  }
  free(est->samplers);
  Freq_Destroy(est->freq);
  free_heap(est->prim_heap);
  free_naivesymtab(est->hashtable);
  free(est);
}
Ejemplo n.º 6
0
void free_pwdb(PWDB *db) {
	uint32_t i;
	PWcontig *pw;

	for (i = 0; i < count_pwctglist(db->pwctgs); i++) {
		pw = get_pwctglist(db->pwctgs, i);
		free(pw);
	}
	free_pwctglist(db->pwctgs);
	free_heap(db->hp);
	
	free(db);
}
Ejemplo n.º 7
0
int main() {

    Node* nodes = calloc(N, sizeof(Node));

    struct Heap heap;
    heap_init(&heap, nodes, N, D);

    pcg32_random_t rng1;
    pcg32_srandom_r(&rng1, time(NULL), (intptr_t)&rng1);

    for (int i = 0; i < N; i++) {
        Node* newnode = heap.nodes + i;
        newnode->id = i + 1;
        newnode->min_edge = 100 * (float) pcg32_random_r(&rng1) / UINT32_MAX;
    }

    heap_number(&heap);

    printf("unordered: \n");
    print_heap(&heap);

    min_heapify(&heap);

    printf("ordered: \n");
    print_heap(&heap);

    printf("min: %f\n\n", heap_find_min(&heap).min_edge);

    heap_deletemin(&heap);

    printf("deletemin: \n");
    print_heap(&heap);

    Node n = {.min_edge = 2.0, .id = heap.n + 1};

    heap_insert(&heap, n);

    printf("\ninsert: \n");
    print_heap(&heap);

    /*for (int i = 0; i < N; i++) {
        printf("min: %f\n\n", heap_find_min(&heap).min_edge);
        heap_deletemin(&heap);
        printHeap(&heap);
    }
*/
    free_heap(&heap);

}
Ejemplo n.º 8
0
Stats terminate(VM* vm) {
    Stats stats = vm->stats;
    STATS_ENTER_EXIT(stats)

    free(vm->inbox);
    free(vm->valstack);
    free_heap(&(vm->heap));

    pthread_mutex_destroy(&(vm -> inbox_lock));
    pthread_mutex_destroy(&(vm -> inbox_block));
    pthread_cond_destroy(&(vm -> inbox_waiting));
    free(vm);

    STATS_LEAVE_EXIT(stats)
    return stats;
}
Ejemplo n.º 9
0
void BpMemoryHeap::assertMapped() const
{
    if (mHeapId == -1) {
        sp<IBinder> binder(const_cast<BpMemoryHeap*>(this)->asBinder());
        sp<BpMemoryHeap> heap(static_cast<BpMemoryHeap*>(find_heap(binder).get()));
        heap->assertReallyMapped();
        if (heap->mBase != MAP_FAILED) {
            Mutex::Autolock _l(mLock);
            if (mHeapId == -1) {
                mBase   = heap->mBase;
                mSize   = heap->mSize;
                android_atomic_write( dup( heap->mHeapId ), &mHeapId );
            }
        } else {
            // something went wrong
            free_heap(binder);
        }
    }
}
Ejemplo n.º 10
0
int main()
{
	int option;
	setbuf(stdin, 0);
	setbuf(stdout,0);
	setbuf(stderr,0);
	while(1){
		puts("1 - new\n2 - edit\n3 - print\n4 - free\n5 - name\n6 - exit\ninput:");
		scanf("%d", &option);
		switch(option){
			case 1: new_heap(); break;
			case 2: edit_heap(); break;
			case 3: print_heap(); break;
			case 4: free_heap(); break;
			case 5: input_name(); break;
			case 6: exit(0); break;
			default: puts("error!\n");
		}
	}
}
Ejemplo n.º 11
0
Stats terminate(VM* vm) {
    Stats stats = vm->stats;
    STATS_ENTER_EXIT(stats)
#ifdef HAS_PTHREAD
    free(vm->inbox);
#endif
    free(vm->valstack);
    free_heap(&(vm->heap));
#ifdef HAS_PTHREAD
    pthread_mutex_destroy(&(vm -> inbox_lock));
    pthread_mutex_destroy(&(vm -> inbox_block));
    pthread_cond_destroy(&(vm -> inbox_waiting));
#endif
    // free(vm);
    // Set the VM as inactive, so that if any message gets sent to it
    // it will not get there, rather than crash the entire system.
    // (TODO: We really need to be cleverer than this if we're going to
    // write programs than create lots of threads...)
    vm->active = 0;

    STATS_LEAVE_EXIT(stats)
    return stats;
}
BpMemoryHeap::~BpMemoryHeap() {
    if (mHeapId != -1) {
        close(mHeapId);
        if (mRealHeap) {
            // by construction we're the last one
            if (mBase != MAP_FAILED) {
                sp<IBinder> binder = IInterface::asBinder(this);

                if (VERBOSE) {
                    ALOGD("UNMAPPING binder=%p, heap=%p, size=%zu, fd=%d",
                            binder.get(), this, mSize, mHeapId);
                    CallStack stack(LOG_TAG);
                }

                munmap(mBase, mSize);
            }
        } else {
            // remove from list only if it was mapped before
            sp<IBinder> binder = IInterface::asBinder(this);
            free_heap(binder);
        }
    }
}
Ejemplo n.º 13
0
void HeapCache::free_heap(const sp<IBinder>& binder)  {
    free_heap( wp<IBinder>(binder) );
}
Ejemplo n.º 14
0
void HeapCache::binderDied(const wp<IBinder>& binder)
{
    //ALOGD("binderDied binder=%p", binder.unsafe_get());
    free_heap(binder);
}
Ejemplo n.º 15
0
/*
 * Free all memory related to my_m.
 *
 */
void free_manager()
{
  my_clause** clauses = my_m->original_clauses;
  int size = my_m->cur_cc;
  //free original clauses.
  for(int j=0; j<size; j++) {
    my_clause* clause = clauses[j];
    free(clause->lits);
    free(clause);
  }
  
  free(my_m->original_clauses); /* this takes care of freeing individual clause structures */

  clauses = my_m->learned_clauses;
  size = my_m->cur_cdc_count;
  //free learned clauses
  for(int j=0; j<size; j++) {
    my_clause* clause = clauses[j];
    if(clause!=NULL){
      free(clause->lits);
      free(clause);
    }
  }
  
  free(my_m->learned_clauses); /* this takes care of freeing individual clause structures */

  size = my_m->vc*2;
  my_clause*** watched = my_m->watched;
  for(int i=0;i<size;i++){
    my_clause** w = watched[i];
    free(w);
  }

  free(my_m->watched);
  free(my_m->watched_len);
  free(my_m->watched_size);

  free(my_m->cdc);
  free(my_m->assign);
  free(my_m->decision_lit);
  free(my_m->score);
  free(my_m->reason);
  free(my_m->status);
  free(my_m->level);

  if(my_m->seen!=NULL){
    free(my_m->seen);
  }
  
  free(my_m->saved);

#if(VERIFY_SOLUTION)
  free(my_m->solution_stack);
#endif
  
  free(my_m->stack);
  free(my_m->save);
  
  free_heap(my_m->var_order_heap);
  free(my_m->var_order_heap);
  
  free(my_m->learned_clause_scores);
  
  free_heap(my_m->imp);
  free(my_m->imp);
  
  free(my_m);
}//end function free_manager