Exemplo n.º 1
0
int main(){
	// struct node *ptr1;
	
	ptr = NULL;

	for(int i=1; i<=10; i++){
		struct node *temp = (struct node*)malloc(sizeof(struct node*));
		temp -> value=i;
		temp -> next=NULL;
		insertIntoLL(temp);
	}

	struct node *temp = (struct node*)malloc(sizeof(struct node*));
	temp -> value=4;
	temp -> next=NULL;
	insertIntoLL(temp);

	struct node *temp1 = (struct node*)malloc(sizeof(struct node*));
	temp1 -> value=11;
	temp1 -> next=NULL;
	insertIntoLL(temp1);

	struct node* runner = ptr;
	int a[20];
	int length = 0, j;

	
}
Exemplo n.º 2
0
SmallArena::ThreadBlockCache::~ThreadBlockCache() {
    LOCK_REGION(heap->lock);

    for (int i = 0; i < NUM_BUCKETS; i++) {
        while (Block* b = cache_free_heads[i]) {
            removeFromLLAndNull(b);
            insertIntoLL(&small->heads[i], b);
        }

        while (Block* b = cache_full_heads[i]) {
            removeFromLLAndNull(b);
            insertIntoLL(&small->full_heads[i], b);
        }
    }
}
Exemplo n.º 3
0
GCAllocation* SmallArena::_alloc(size_t rounded_size, int bucket_idx) {
    Block** free_head = &heads[bucket_idx];
    Block** full_head = &full_heads[bucket_idx];

    static __thread ThreadBlockCache* cache = NULL;
    if (!cache)
        cache = thread_caches.get();

    Block** cache_head = &cache->cache_free_heads[bucket_idx];

    // static __thread int gc_allocs = 0;
    // if (++gc_allocs == 128) {
    // static StatCounter sc_total("gc_allocs");
    // sc_total.log(128);
    // gc_allocs = 0;
    //}

    while (true) {
        while (Block* cache_block = *cache_head) {
            GCAllocation* rtn = _allocFromBlock(cache_block);
            if (rtn)
                return rtn;

            removeFromLLAndNull(cache_block);
            insertIntoLL(&cache->cache_full_heads[bucket_idx], cache_block);
        }

        // Not very useful to count the cache misses if we don't count the total attempts:
        // static StatCounter sc_fallback("gc_allocs_cachemiss");
        // sc_fallback.log();

        LOCK_REGION(heap->lock);

        assert(*cache_head == NULL);

        // should probably be called allocBlock:
        Block* myblock = _claimBlock(rounded_size, &heads[bucket_idx]);
        assert(myblock);
        assert(!myblock->next);
        assert(!myblock->prev);

        // printf("%d claimed new block %p with %d objects\n", threading::gettid(), myblock, myblock->numObjects());

        insertIntoLL(cache_head, myblock);
    }
}
Exemplo n.º 4
0
void SmallArena::freeUnmarked(std::vector<Box*>& weakly_referenced) {
    thread_caches.forEachValue([this, &weakly_referenced](ThreadBlockCache* cache) {
        for (int bidx = 0; bidx < NUM_BUCKETS; bidx++) {
            Block* h = cache->cache_free_heads[bidx];
            // Try to limit the amount of unused memory a thread can hold onto;
            // currently pretty dumb, just limit the number of blocks in the free-list
            // to 50.  (blocks in the full list don't need to be limited, since we're sure
            // that the thread had just actively used those.)
            // Eventually may want to come up with some scrounging system.
            // TODO does this thread locality even help at all?
            for (int i = 0; i < 50; i++) {
                if (h)
                    h = h->next;
                else
                    break;
            }
            if (h) {
                removeFromLLAndNull(h);
                insertIntoLL(&heads[bidx], h);
            }

            Block** chain_end = _freeChain(&cache->cache_free_heads[bidx], weakly_referenced);
            _freeChain(&cache->cache_full_heads[bidx], weakly_referenced);

            while (Block* b = cache->cache_full_heads[bidx]) {
                removeFromLLAndNull(b);
                insertIntoLL(chain_end, b);
            }
        }
    });

    for (int bidx = 0; bidx < NUM_BUCKETS; bidx++) {
        Block** chain_end = _freeChain(&heads[bidx], weakly_referenced);
        _freeChain(&full_heads[bidx], weakly_referenced);

        while (Block* b = full_heads[bidx]) {
            removeFromLLAndNull(b);
            insertIntoLL(chain_end, b);
        }
    }
}
Exemplo n.º 5
0
int main(){
	// struct node *ptr1;
	
	ptr = NULL;

	for(int i=1; i<=10; i++){
		struct node *temp = (struct node*)malloc(sizeof(struct node*));
		temp -> value=i;
		temp -> next=NULL;
		insertIntoLL(temp);
	}

	struct node *temp = (struct node*)malloc(sizeof(struct node*));
	temp -> value=4;
	temp -> next=NULL;
	insertIntoLL(temp);

	struct node *temp1 = (struct node*)malloc(sizeof(struct node*));
	temp1 -> value=11;
	temp1 -> next=NULL;
	insertIntoLL(temp1);
	
	
	struct node *runner1, *runner2;
	runner1 = runner2 = ptr;

	while(runner1!=NULL){
		runner2 = runner1->next;
		while(runner2!=NULL){
			if(runner1->value==runner2->value){
				delete1(runner2->value);
				runner2=runner2->next;
			}
			runner2=runner2->next;
		}
		runner1=runner1->next;
	}

	printLL();
}
Exemplo n.º 6
0
GCAllocation* LargeArena::alloc(size_t size) {
    registerGCManagedBytes(size);

    LOCK_REGION(heap->lock);

    // printf ("allocLarge %zu\n", size);

    LargeObj* obj = _alloc(size + sizeof(GCAllocation) + sizeof(LargeObj));

    obj->size = size;

    nullNextPrev(obj);
    insertIntoLL(&head, obj);

    return obj->data;
}