コード例 #1
0
ファイル: set02.cpp プロジェクト: ABratovic/open-watcom-v2
int main( )
{
    int rc = 0;
    //heap_dump();
    int original_count = heap_count( );
    
    try {
        if( !construct_test( )  || !heap_ok( "t1" ) ) rc = 1;
        if( !access_test( )     || !heap_ok( "t2" ) ) rc = 1;
        //if( !string_test( )     || !heap_ok( "t3" ) ) rc = 1;
        //if( !torture_test( )    || !heap_ok( "t4" ) ) rc = 1;
        //if( !clear_test( )      || !heap_ok( "t5" ) ) rc = 1;
        if( !iterator_test( )   || !heap_ok( "t6" ) ) rc = 1;
        if( !copy_test( )       || !heap_ok( "t7" ) ) rc = 1;
        if( !allocator_test( )  || !heap_ok( "t8" ) ) rc = 1;
        if( !bounds_test( )     || !heap_ok( "t9" ) ) rc = 1;
        if( !hint_ins_test( )   || !heap_ok( "tA" ) ) rc = 1;
    }
    catch( ... ) {
        std::cout << "Unexpected exception of unexpected type.\n";
        rc = 1;
    }
    int heap_diff = heap_count( ) - original_count;
    if( heap_diff ) {
        heap_dump();
        std::cout << "Possible memory leak! " << heap_diff << " " << original_count << "\n";
        rc = 1;
    }
    
    return( rc );
}
コード例 #2
0
ファイル: gc.c プロジェクト: hsk/docs
void gc_sweep(VM* _vm) {
    ObjectHeader** object = &(vm->heap_list);
    debug2("object =%p\n", object);
    while (*object) {
        if (!(*object)->marked) {
            ObjectHeader* unreached = *object;
            *object = unreached->next;

            if(unreached->type == OBJ_VM) vm_finalize((VM*)&unreached[1]);

            free(unreached);

            vm->heap_num--;
        } else {
            (*object)->marked = 0;
            if(_vm) {
                printf("gc sweep vm\n");
                ObjectHeader* moving = *object;
                *object = moving->next;
                debug2("id change\n");
                _vm->heap_num++;
                moving->next = _vm->heap_list;
                _vm->heap_list = moving;
                printf("heap_num %ld %ld\n", _vm->heap_num, heap_count(_vm->heap_list));
                assert(_vm->heap_num == heap_count(_vm->heap_list));
            } else {
                object = &(*object)->next;
            }
        }
    }
}
コード例 #3
0
ファイル: batch_monitor.c プロジェクト: willemt/bmon
static void __batcher_loop(void *n)
{
    batch_monitor_t* m = n;

    uv_mutex_lock(&m->lock);
    batch_queue_t *bq = &m->queues[m->curr_idx];
    batch_queue_t *prev_bq =
        &m->queues[(m->curr_idx + 1) % MAX_BATCH_QUEUES];
    if (0 < prev_bq->puts_waiting || 0 == heap_count(bq->queue))
    {
        struct timespec tim, tim2;
        tim.tv_sec = 0;
        tim.tv_nsec = m->nanos;

        if (nanosleep(&tim, &tim2) < 0)
            printf("Nano sleep system call failed \n");

        uv_mutex_unlock(&m->lock);
        return;
    }
    m->commit(m, bq);
    m->curr_idx = (m->curr_idx + 1) % MAX_BATCH_QUEUES;
    uv_mutex_unlock(&m->lock);
    uv_cond_signal(&m->done);
}
コード例 #4
0
ファイル: string01.cpp プロジェクト: ABratovic/open-watcom-v2
int main( )
{
  int rc = 0;
  int original_count = heap_count( );

  try {
    if( !construct_test( )         || !heap_ok( "t01" ) ) rc = 1;
    if( !assign_test( )            || !heap_ok( "t02" ) ) rc = 1;
    if( !access_test( )            || !heap_ok( "t03" ) ) rc = 1;
    if( !relational_test( )        || !heap_ok( "t04" ) ) rc = 1;
    if( !capacity_test( )          || !heap_ok( "t05" ) ) rc = 1;
    if( !iterator_test( )          || !heap_ok( "t06" ) ) rc = 1;
    if( !append_test( )            || !heap_ok( "t07" ) ) rc = 1;
    if( !insert_test( )            || !heap_ok( "t08" ) ) rc = 1;
    if( !erase_test( )             || !heap_ok( "t09" ) ) rc = 1;
    if( !replace_test( )           || !heap_ok( "t10" ) ) rc = 1;
    if( !iterator_replace_test( )  || !heap_ok( "t11" ) ) rc = 1;
    if( !copy_test( )              || !heap_ok( "t12" ) ) rc = 1;
    if( !swap_test( )              || !heap_ok( "t13" ) ) rc = 1;
    if( !cstr_test( )              || !heap_ok( "t14" ) ) rc = 1;
    if( !find_test( )              || !heap_ok( "t15" ) ) rc = 1;
    if( !rfind_test( )             || !heap_ok( "t16" ) ) rc = 1;
    if( !find_first_of_test( )     || !heap_ok( "t17" ) ) rc = 1;
    if( !find_last_of_test( )      || !heap_ok( "t18" ) ) rc = 1;
    if( !find_first_not_of_test( ) || !heap_ok( "t19" ) ) rc = 1;
    if( !find_last_not_of_test( )  || !heap_ok( "t20" ) ) rc = 1;
    if( !substr_test( )            || !heap_ok( "t21" ) ) rc = 1;
  }
  catch( std::out_of_range e ) {
    std::cout << "Unexpected out_of_range exception: " << e.what( ) << "\n";
    rc = 1;
  }
  catch( std::length_error e ) {
    std::cout << "Unexpected length_error exception: " << e.what( ) << "\n";
    rc = 1;
  }
  catch( ... ) {
    std::cout << "Unexpected exception of unexpected type.\n";
    rc = 1;
  }

  if( heap_count( ) != original_count ) {
    std::cout << "Possible memory leak!\n";
    rc = 1;
  }
  return( rc );
}
コード例 #5
0
int main( )
{
  int rc = 0;
  int original_count = heap_count( );

  try {
    if( !some_test( )    || !heap_ok( "t01" ) ) rc = 1;
  }
  catch( ... ) {
    std::cout << "Unexpected exception of unexpected type.\n";
    rc = 1;
  }

  if( heap_count( ) != original_count ) {
    std::cout << "Possible memory leak!\n";
    rc = 1;
  }
  return( rc );
}
コード例 #6
0
ファイル: heap.c プロジェクト: rsennrich/Wapiti
/**
 * @return the item on the top of the heap */
void *heap_peek(heap_t * hp)
{
    if (!hp)
	return NULL;

    if (0 == heap_count(hp))
	return NULL;

    return hp->array[0];
}
コード例 #7
0
ファイル: main.c プロジェクト: Knight-X/pearldb
static int __batcher_commit(batch_monitor_t* m, batch_queue_t* bq)
{
    if (0 == heap_count(bq->queue))
        return 0;

    MDB_txn *txn;

    int e = mdb_txn_begin(sv->db_env, NULL, 0, &txn);
    if (0 != e)
        mdb_fatal(e);

    while (0 < heap_count(bq->queue))
    {
        batch_item_t* item = heap_poll(bq->queue);
        e = mdb_put(txn, sv->docs, &item->key, &item->val, item->flags);
        switch (e)
        {
        case 0:
            break;
        case MDB_MAP_FULL:
        {
            mdb_txn_abort(txn);
            while ((item = heap_poll(bq->queue)))
                ;
            snprintf(batcher_error, BATCHER_ERROR_LEN, "NOT ENOUGH SPACE");
            return -1;
        }
        case MDB_KEYEXIST:
            item->flags = WOULD_OVERWRITE;
            break;
        default:
            mdb_fatal(e);
        }
    }

    e = mdb_txn_commit(txn);
    if (0 != e)
        mdb_fatal(e);

    return 0;
}
コード例 #8
0
ファイル: queue01.cpp プロジェクト: ABratovic/open-watcom-v2
int main( )
{
    int rc = 0;
    int original_count = heap_count( );

    try {
        if( !basic_test< std::deque< int > >( )  || !heap_ok( "t01" ) ) rc = 1;
        if( !basic_test< std::list< int > >( )   || !heap_ok( "t02" ) ) rc = 1;
        if( !relational_test( )                  || !heap_ok( "t03" ) ) rc = 1;
        if( !basic_priority_test( )              || !heap_ok( "t04" ) ) rc = 1;
    }
    catch( ... ) {
        std::cout << "Unexpected exception of unexpected type.\n";
        rc = 1;
    }

    if( heap_count( ) != original_count ) {
        std::cout << "Possible memory leak!\n";
        rc = 1;
    }
    return( rc );
}
コード例 #9
0
ファイル: heap.c プロジェクト: srsbsns/libsrsbsns
static bool
heap_resize(heap_t h, size_t newsz)
{
	if (!newsz)
		newsz = 1;

	if (newsz < heap_count(h))
		return false;

	void **newloc = realloc(h->tree, newsz * sizeof *newloc);
	if (!newloc)
		return false;

	h->tree = newloc;
	h->treesz = newsz;
	return true;
}
コード例 #10
0
ファイル: r_vbo_square_pw.c プロジェクト: willemt/tearen
/** 
 * Find a slot that is free on this VBO
 * @return a new item slot on this VBO
 */
int ren_vbosquare_new_itemslot(const int id)
{
    vbo_t *vb = __get_vbo_from_id(id);

    /* if the heap is empty just use the most latest slot */
    if (0 == heap_count(vb->heap))
    {
	assert(vb->n_length_inuse < vb->n_elem);
	return vb->n_length_inuse++;
    }
    else
    {
	unsigned long slot;

	slot = (unsigned long) heap_poll(vb->heap);

	return slot;
    }
}
コード例 #11
0
ファイル: r_vbo_managed.c プロジェクト: willemt/tearen
/** 
 * Find a slot that is free on this VBO
 * @return a new item slot on this VBO
 */
int ren_vbom_new_itemslot(
    const int id
)
{
    vbo_t *vb = __get_vbo_from_id(id);

    if (0 == heap_count(vb->heap))
    {
        assert(vb->n_length_inuse < vb->n_elem);
        return vb->n_length_inuse++;
    }
    else
    {
        unsigned long slot;

        slot = (unsigned long) heap_poll(vb->heap);

        return slot;
    }
}
コード例 #12
0
ファイル: heap.c プロジェクト: rsennrich/Wapiti
/**
 * Remove the top value from this heap.
 * @return top item of the heap */
void *heap_poll(heap_t * hp)
{
    void *item;

    assert(hp);

    if (!hp)
	return NULL;

    if (0 == heap_count(hp))
	return NULL;

#if DEBUG
    DEBUG_check_validity(hp);
#endif

    item = hp->array[0];

    hp->array[0] = NULL;
    __swap(hp, 0, hp->count - 1);
    hp->count--;

#if DEBUG
    DEBUG_check_validity(hp);
#endif

    if (hp->count > 0)
    {
	assert(hp->array[0]);
	__pushdown(hp, 0);
    }

#if DEBUG
    DEBUG_check_validity(hp);
#endif

    return item;
}
コード例 #13
0
ファイル: priqueue.c プロジェクト: simplyzhao/Code_Pearls
int
priqueue_count(struct PriQueue *priqueue)
{
	assert(priqueue != NULL);
	return heap_count(priqueue->heap);
}
コード例 #14
0
ファイル: compute-unit.c プロジェクト: vtselfa/Multi2Sim
void evg_compute_unit_free(struct evg_compute_unit_t *compute_unit)
{
	struct heap_t *event_queue;
	struct evg_uop_t *uop;
	int i;

	/* CF Engine - free uops in fetch buffer, instruction buffer, and complete queue */
	for (i = 0; i < evg_gpu_max_wavefronts_per_compute_unit; i++)
	{
		evg_uop_free(compute_unit->cf_engine.fetch_buffer[i]);
		evg_uop_free(compute_unit->cf_engine.inst_buffer[i]);
	}
	evg_uop_list_free(compute_unit->cf_engine.complete_queue);

	/* CF Engine - free structures */
	free(compute_unit->cf_engine.fetch_buffer);
	free(compute_unit->cf_engine.inst_buffer);
	linked_list_free(compute_unit->cf_engine.complete_queue);

	/* ALU Engine - free uops in event queue (heap) */
	event_queue = compute_unit->alu_engine.event_queue;
	while (heap_count(event_queue))
	{
		heap_extract(event_queue, (void **) &uop);
		uop->write_subwavefront_count++;
		if (uop->write_subwavefront_count == uop->subwavefront_count)
			evg_uop_free(uop);
	}

	/* ALU Engine - free uops in fetch queue, instruction buffer, execution buffer,
	 * and event queue. Also free CF instruction currently running. */
	evg_uop_list_free(compute_unit->alu_engine.pending_queue);
	evg_uop_list_free(compute_unit->alu_engine.finished_queue);
	evg_uop_list_free(compute_unit->alu_engine.fetch_queue);
	evg_uop_free(compute_unit->alu_engine.inst_buffer);
	evg_uop_free(compute_unit->alu_engine.exec_buffer);

	/* ALU Engine - structures */
	linked_list_free(compute_unit->alu_engine.pending_queue);
	linked_list_free(compute_unit->alu_engine.finished_queue);
	linked_list_free(compute_unit->alu_engine.fetch_queue);
	heap_free(compute_unit->alu_engine.event_queue);

	/* TEX Engine - free uop in fetch queue, instruction buffer, write buffer. */
	evg_uop_list_free(compute_unit->tex_engine.pending_queue);
	evg_uop_list_free(compute_unit->tex_engine.finished_queue);
	evg_uop_list_free(compute_unit->tex_engine.fetch_queue);
	evg_uop_free(compute_unit->tex_engine.inst_buffer);
	evg_uop_list_free(compute_unit->tex_engine.load_queue);

	/* TEX Engine - structures */
	linked_list_free(compute_unit->tex_engine.pending_queue);
	linked_list_free(compute_unit->tex_engine.finished_queue);
	linked_list_free(compute_unit->tex_engine.fetch_queue);
	linked_list_free(compute_unit->tex_engine.load_queue);

	/* Compute unit */
	linked_list_free(compute_unit->wavefront_pool);
	free(compute_unit->work_groups);  /* List of mapped work-groups */
	mod_free(compute_unit->local_memory);
	free(compute_unit);
}
コード例 #15
0
ファイル: query.c プロジェクト: ceyhunkerti/RediSearch
QueryResult *Query_Execute(Query *query) {
    //__queryStage_Print(query->root, 0);
    QueryResult *res = malloc(sizeof(QueryResult));
    res->error = 0;
    res->errorString = NULL;
    res->totalResults = 0;
    res->ids = NULL;
    res->numIds = 0;

    int num = query->offset + query->limit;
    heap_t *pq = malloc(heap_sizeof(num));
    heap_init(pq, cmpHits, NULL, num);

    //  start lazy evaluation of all query steps
    IndexIterator *it = NULL;
    if (query->root != NULL) {
        it = Query_EvalStage(query, query->root);
    }

    // no query evaluation plan?
    if (query->root == NULL || it == NULL) {
        res->error = QUERY_ERROR_INTERNAL;
        res->errorString = QUERY_ERROR_INTERNAL_STR;
        return res;
    }

    IndexHit *pooledHit = NULL;
    // iterate the root iterator and push everything to the PQ
    while (1) {
        // TODO - Use static allocation
        if (pooledHit == NULL) {
            pooledHit = malloc(sizeof(IndexHit));
        }
        IndexHit *h = pooledHit;
        IndexHit_Init(h);
        int rc = it->Read(it->ctx, h);

        if (rc == INDEXREAD_EOF) {
            break;
        } else if (rc == INDEXREAD_NOTFOUND) {
            continue;
        }

        h->totalFreq = processHitScore(h, query->docTable);

        ++res->totalResults;

        if (heap_count(pq) < heap_size(pq)) {
            heap_offerx(pq, h);
            pooledHit = NULL;
        } else {
            IndexHit *qh = heap_peek(pq);
            if (qh->totalFreq < h->totalFreq) {
                pooledHit = heap_poll(pq);
                heap_offerx(pq, h);
                // IndexHit_Terminate(pooledHit);
            } else {
                pooledHit = h;
                // IndexHit_Terminate(pooledHit);
            }
        }
    }

    if (pooledHit) {
        free(pooledHit);
    }

    it->Free(it);

    // Reverse the results into the final result
    size_t n = MIN(heap_count(pq), query->limit);
    res->numIds = n;
    res->ids = calloc(n, sizeof(RedisModuleString *));

    for (int i = 0; i < n; ++i) {
        IndexHit *h = heap_poll(pq);
        LG_DEBUG("Popping %d freq %f", h->docId, h->totalFreq);
        res->ids[n - i - 1] = Redis_GetDocKey(query->ctx, h->docId);
        free(h);
    }

    // if we still have something in the heap (meaning offset > 0), we need to
    // poll...
    while (heap_count(pq) > 0) {
        IndexHit *h = heap_poll(pq);
        free(h);
    }

    heap_free(pq);
    return res;
}
コード例 #16
0
ファイル: shell.c プロジェクト: ConcoMB/TP-Arq
void print_memory(){
	int s = stack_count();
	int h = heap_count();
	printf("\nSTACK:\n %d bytes used\n", s);
	printf("\n HEAP:\n %d pages used -> %d bytes\n\n", h, h*4096);
}