Exemplo n.º 1
0
/**********************************************************
 * mm_malloc
 * Allocate a block of size bytes.
 * The type of search is determined by find_fit
 * The decision of splitting the block, or not is determined
 *   in place(..)
 * If no block satisfies the request, the heap is extended
 **********************************************************/
void *mm_malloc(size_t size)
{
	//mm_check();
	//print_seg(0);
//	printf("IN MALLOC\n");
    size_t asize; /* adjusted block size */
    size_t extendsize; /* amount to extend heap if no fit */
    char * bp;

    /* Ignore spurious requests */
    if (size == 0)
        return NULL;

    /* Adjust block size to include overhead and alignment reqs. */
    if (size <= DSIZE)
        asize = 2 * DSIZE;
    else
        asize = DSIZE * ((size + (DSIZE) + (DSIZE-1))/ DSIZE);

    /* Search the free list for a fit */
    if ((bp = find_segregated_best_fit(asize)) != NULL) {

    	//printf("free size found, bp is %p\n",bp);
    	remove_free_block(bp);
        place(bp, asize);
        return bp;
    };

    /* No fit found. Get more memory and place the block */
    extendsize = MAX(asize, CHUNKSIZE);
    if ((bp = extend_heap(extendsize/WSIZE)) == NULL)
    {
        return NULL;
    }
    place(bp, asize);
    return bp;

}
Exemplo n.º 2
0
Arquivo: ed.c Projeto: 00001/plan9port
void
dosub(void)
{
	Rune *lp, *sp, *rp;
	int c, n;

	lp = linebuf;
	sp = genbuf;
	rp = rhsbuf;
	while(lp < loc1)
		*sp++ = *lp++;
	while(c = *rp++) {
		if(c == '&'){
			sp = place(sp, loc1, loc2);
			continue;
		}
		if(c == ESCFLG && (c = *rp++) >= '1' && c < MAXSUB+'0') {
			n = c-'0';
			if(subexp[n].s.rsp && subexp[n].e.rep) {
				sp = place(sp, subexp[n].s.rsp, subexp[n].e.rep);
				continue;
			}
			error(Q);
		}
		*sp++ = c;
		if(sp >= &genbuf[LBSIZE])
			error(Q);
	}
	lp = loc2;
	loc2 = sp - genbuf + linebuf;
	while(*sp++ = *lp++)
		if(sp >= &genbuf[LBSIZE])
			error(Q);
	lp = linebuf;
	sp = genbuf;
	while(*lp++ = *sp++)
		;
}
Exemplo n.º 3
0
/* 
 * mm_malloc - Allocate a block by incrementing the brk pointer.
 *     Always allocate a block whose size is a multiple of the alignment.
 */
void *mm_malloc(size_t size)
{
    /*int newsize = ALIGN(size + SIZE_T_SIZE);
    void *p = mem_sbrk(newsize);
    if (p == (void *)-1)
	return NULL;
    else {
        *(size_t *)p = size;
        return (void *)((char *)p + SIZE_T_SIZE);
    } */

	size_t asize;
	size_t extendsize;
	char *bp;

	//ignore spurious requests
	if(size == 0)
		return NULL;
	
	//adjust block size to include overhead and alignment reqs
	if(size <= DSIZE)
		asize = 2*DSIZE;
	else
		asize = DSIZE * ((size + (DSIZE) + (DSIZE-1)) / DSIZE);

	//search the free list for a fit
	if((bp = find_fit(asize)) != NULL) {
		place(bp, asize);
		return bp;
	}

	//no fit found, get more memory and place the block
	extendsize = MAX(asize, CHUNKSIZE);
	if((bp = extend_heap(extendsize/WSIZE)) == NULL)
		return NULL;
	place(bp, asize);
	return bp;
}
Exemplo n.º 4
0
 void place(int *arr, int n, int k, int &count){
     if(k == n){
         ++count;
         return;
     }
     else{
         for(int i = 0; i != n; ++i){
             if(check(arr, n, k, i)){
                 arr[k] = i;
                 place(arr, n, k+1, count);
             }
         }
     }
 }
Exemplo n.º 5
0
void scroll_label::set_label(const t_string& lbl)
{
	// Inherit.
	styled_widget::set_label(lbl);

	if(label* widget = get_internal_label()) {
		widget->set_label(lbl);

		bool resize_needed = !content_resize_request();
		if(resize_needed && get_size() != point()) {
			place(get_origin(), get_size());
		}
	}
}
Exemplo n.º 6
0
Arquivo: main.cpp Projeto: CCJY/coliru
		optional& operator=( const optional& that ) {
			if ( std::addressof( that ) == this )
				return *this;
			if ( present && that.present )
				**this = *that;
			else if ( present )
				destroy( );
			else if ( that.present )
				place( *that );
			else
				present = false;

			return *this;
		}
Exemplo n.º 7
0
Arquivo: main.cpp Projeto: CCJY/coliru
		optional& operator=( optional&& that ) {
			if ( std::addressof( that ) == this )
				return *this;
			if ( present && that.present )
				value( ) = std::move( that.value( ) );
			else if ( present )
				destroy( );
			else if ( that.present )
				place( std::move( *that ) );
			else
				present = false;

			return *this;
		}
ConnectionDialog::ConnectionDialog(const std::string &text,
                                   const State cancelState):
    Window(""),
    gcn::ActionListener(),
    mCancelState(cancelState)
{
    setTitleBarHeight(0);
    setMovable(false);
    setMinWidth(0);

    ProgressIndicator *const progressIndicator = new ProgressIndicator;
    Label *const label = new Label(this, text);
    Button *const cancelButton = new Button(
        // TRANSLATORS: connection dialog button
        this, _("Cancel"), "cancelButton", this);

    place(0, 0, progressIndicator);
    place(0, 1, label);
    place(0, 2, cancelButton).setHAlign(LayoutCell::CENTER);
    reflowLayout();

    center();
}
Exemplo n.º 9
0
Arquivo: 2.c Projeto: heyuhang/linuxC
 int queen(int t)   
 {   
   int i;
     if(t>n && n>0) //当放置的皇后超过n时,可行解个数加1,此时n必须大于0   
       sum++;   
     else  
       for( i=1;i<=n;i++)   
       {   
           x[t] = i; //标明第t个皇后放在第i列   
           if(place(t)) //如果可以放在某一位置,则继续放下一皇后   
             queen(t+1);    
       }   
     return sum;   
 }   
Exemplo n.º 10
0
		optional& operator=(const optional& that) {
			if (std::addressof(that) == this)
				return *this;
			if (valid() && that.valid())
				**this = *that;
			else if (valid())
				unchecked_destroy();
			else if (that.valid())
				place(*that);
			else
				present = false;

			return *this;
		}
Exemplo n.º 11
0
int solve(int mask, int r, int c) {
  if( r == n ) return 1;

  int nr = (c == n-1 ? r+1 : r), nc = (c == n-1 ? 0 : c+1);

  if( !empty[r][c] ) {
    if( ok(r, c, a[r][c]) ) {
      place(r, c, a[r][c]);
      return solve(mask | (1<<a[r][c]), nr, nc);
    }
    return 0;
  }

  for( int i = square_of_n; i > 0; --i )
    if( !((1<<i) & mask) && ok(r, c, i) ) {
      place(r, c, i);
      int found = solve(mask | (1<<i), nr, nc);
      if( found ) return 1;
      else remove(r, c, i);
    }

  return 0;
}
Exemplo n.º 12
0
void    Amt::DiagLImpl::applyAttrs(){
	crtc::ItemNode::applyAttrs();
        visible( 1 );
	gtk_widget_show_all(_in_widget);
	if( uart = dynamic_cast<riku::Iuart*>(riku::stdRegister::getRegister().getUart()) ){
	    apply = true;
	    if ((_in_mod_id != "") && !_in_place.length() )
		place((std::string("Место: ")+std::string(uart->get_mPlace(_in_mod_id)) ).c_str() );
	    registerForStep__( );
	}
	else	
	    std::cout<<"\t dynamic_cast crtc::DiagLImpl->Amt::UartImpl ERROR\n";

}
Exemplo n.º 13
0
//place a queen in a col of the row
void place(int *pos, int row)
{
	int j;

	for (j = 0; j < N; j++) {
		if (can_place(pos, row, j)) {
			pos[row] = j;
			if (row == N-1)
				output(pos);
			else
				place(pos, row+1);
		}
	}
}
Exemplo n.º 14
0
std::string CodeLocation::str () const
{
  char line [50];
  sprintf (line, "%d", m_line);
  std::string place (m_file);
  place += ":";
  place += line;
  if ( strlen(m_function) ) // skip if compiler does not set function
  {
    place += ":";
    place += m_function;
  }
  return place;
}
Exemplo n.º 15
0
void new_player_t::open()
{
	init(gengine);
	place(wmain->x(), wmain->y(), wmain->width(), wmain->height());
	font(B_NORMAL_FONT);
	foreground(wmain->map_rgb(255, 255, 255));
	background(wmain->map_rgb(0, 0, 0));
	memset(name, 0, sizeof(name));
	name[0] = 'A';
	currentIndex = 0;
	editing = 1;
	build_all();
	SDL_EnableUNICODE(1);
}
Exemplo n.º 16
0
void Position::applyMove(Square sq)
{
    place(sq, currentPlayer());

    for (int d = 0; d < TOT_DIR; ++d) {
        if (isValidMove(sq, DIR[d]))
            reverse(sq, DIR[d]);
    }

    ++count[currentPlayer()];
    nullMoveCount = 0;

    changePlayer();
}
Exemplo n.º 17
0
void
dosub(uchar *rhsbuf)
{
	uchar *lp, *sp, *rp;
	int c;

	lp = linebuf;
	sp = genbuf;
	rp = rhsbuf;
	while (lp < loc1)
		*sp++ = *lp++;
	while(c = *rp++) {
		if (c == '\\') {
			c = *rp++;
			if (c >= '1' && c < NBRA+'1') {
				sp = place(sp, braslist[c-'1'], braelist[c-'1']);
				continue;
			}
		} else if(c == '&') {
				sp = place(sp, loc1, loc2);
				continue;
		}
		*sp++ = c;
		if (sp >= &genbuf[LBSIZE])
			fprintf(stderr, "sed: Output line too long.\n");
	}
	lp = loc2;
	loc2 = sp - genbuf + linebuf;
	while (*sp++ = *lp++)
		if (sp >= &genbuf[LBSIZE]) {
			fprintf(stderr, "sed: Output line too long.\n");
		}
	lp = linebuf;
	sp = genbuf;
	while (*lp++ = *sp++);
	spend = lp-1;
}
Exemplo n.º 18
0
/* 
 * mm_malloc - Allocate a block by incrementing the brk pointer.
 *     Always allocate a block whose size is a multiple of the alignment.
 */
void *mm_malloc(size_t size)
{
    size_t asize;
    /*asize = overrall size with overhead + alignment*/
    size_t extendsize;
    char *bp;
#ifdef DEBUG
    printf("[%d] malloc called with %d\n",++mCnt,size);
#endif

    if(size <= 0)
        return NULL;
    if(size <= WSIZE)
        printf("<WISZE\n");

    if(size <= DSIZE)
        asize = DSIZE + OVERHEAD;
    else
        asize = ALIGN(size + OVERHEAD);

    if((bp = find_fit(asize)) != NULL){
#ifdef DEBUG
        printf("find a slot at %d \n",bp-heap_listp);
#endif
        place(bp,asize);
        return bp;
    }
    //Exam_list(asize);
    extendsize = MAX(asize,C4K);

    if((bp = extend_heap(extendsize/WSIZE)) == NULL)
        return NULL;
    place(bp, asize);

    //Exam_list();
    return bp;
}
/*
 * malloc
 */
void *malloc (size_t size) {
    size_t asize;      /* Adjusted block size */
    size_t extendsize; /* Amount to extend heap if no fit */
    char *bp;      

    /* Re-initiate */
    if (first_block == 0){
        mm_init();
    }
    /* Ignore spurious requests */
    if (size == 0)
        return NULL;
    /* Adjust block size to include overhead and alignment*/
    asize = MAX(ALIGN(size + WSIZE), MINSIZE * WSIZE);

    assert(asize >= MINSIZE * WSIZE);

    /* Search the free list for a fit */
    if ((bp = find_fit(asize)) != NULL) {        
        place(bp, asize);                  
#ifdef DEBUG   
        mm_checkheap(1);        
#endif        
        return bp;
    }

    /* No fit found. Get more memory and place the block */
    extendsize = MAX(asize,CHUNKSIZE);                
    if (NULL == (bp = extend_heap(extendsize/WSIZE)))
            return NULL;

    place(bp, asize);                                 
#ifdef DEBUG        
    mm_checkheap(1);    
#endif    
    return bp;
}
Exemplo n.º 20
0
/*
 * malloc: adjust the size to the minimum block size or a
 * multiple of alignment. Search the free list for a fit,
 * if not, extend the heap
 */
void *malloc (size_t size) {
    //checkheap(1);  // Let's make sure the heap is ok!
    size_t asize; // adjust size
    size_t extendsize;
    char *bp;

    if (size <= 0){
        return NULL;
    }

    // Adjust the size to at least the minimum blk size and 
    // a multiple of alignment 8
    if (size <= (DSIZE + WSIZE)){
        asize = 2 * DSIZE;
    }
    else{
        asize = DSIZE*((size + DSIZE + (DSIZE - 1)) / DSIZE);
    }

    // search the freelist for a fit 
    if ((bp = findFit(asize)) != NULL){
        place(bp, asize);
        return bp;
    }

    // If no fit, extend the heap
    if(asize>CHUNKSIZE)
        extendsize = asize;
    else
        extendsize = CHUNKSIZE;

    if ((bp = extendHeap(extendsize / WSIZE)) == NULL)
        return NULL;
    place(bp, asize);

    return bp;
}
Exemplo n.º 21
0
//places an item in the hash table
void put(HashEntry** table, char* alias, char* cmd){
    int key = findKey(alias);
	int hash = (key % TABLE_SIZE);
	HashEntry *curr; //keeps track of place in bucket

    //empty bucket
    if (table[hash] == NULL || curr->key == key){
        table[hash] = malloc(sizeof(HashEntry));
        table[hash]->next = NULL;
        place(table[hash], key, alias, cmd);
    }

    else{
        curr = table[hash]; //curr = root of bucket

        //if alias == first bucket items alias, replace
        if (strcmp(curr->alias, alias) == 0){
            place(curr, key, alias, cmd);
        }

        else{
            while (curr->next != NULL){ //while the next place is not taken
                curr = curr->next;
                if (strcmp(curr->alias, alias) == 0){
                    place(curr, key, alias, cmd);
                    return;
                }
            }

            //new alias
            curr->next = malloc(sizeof(HashEntry));
            curr = curr->next;
            curr->next = NULL;
            place(curr, key, alias, cmd);
        }
    }
}
Exemplo n.º 22
0
/* 
 * mm_malloc - Allocate a block by incrementing the brk pointer.
 *     Always allocate a block whose size is a multiple of the alignment.
 */
void *mm_malloc(size_t size)
{
    /*begin with allocating the first open space
    * Iterate through the heap looking for open space
    * If no open space move sbrk
    * If open space then make a header and footer that bracket the space
    * Encode the space size in the header
    */
    size_t asize; /* Adjusted block size */
    size_t extendsize; /* Amount to extend heap if no fit */
    char *bp;

    /* Ignore spurious requests */
    if (size == 0)
        return NULL;

    /* Adjust block size to include overhead and alignment reqs. */
    if (size <= DSIZE)
        asize = 2*DSIZE;
    else
        asize = DSIZE * ((size + (DSIZE) + (DSIZE-1)) / DSIZE);

    /* Search the free list for a fit (MAKE A FIND FIT)*/
    if ((bp = find_fit(asize)) != NULL) 
    {
        place(bp, asize);
        return bp;
    }

    /* No fit found. Get more memory and place the block */
    extendsize = MAX(asize,CHUNKSIZE);
    if ((bp = extend_heap(extendsize/WSIZE)) == NULL)
        return NULL;
    //MAKE A PLACE
    place(bp, asize);
    return bp;
}
Exemplo n.º 23
0
bool complete_building(Unit &u) {
	if (u.has_attribute(attr_type::building)) {
		auto &build = u.get_attribute<attr_type::building>();
		build.completed = 1.0f;

		// set ground under a completed building
		auto target_location = u.location.get();
		bool placed_ok = target_location->place(build.completion_state);
		if (placed_ok) {
			target_location->set_ground(build.foundation_terrain, 0);
		}
		return placed_ok;
	}
	return false;
}
Exemplo n.º 24
0
Board invert_rotate_for_move(Board og, Move m) {
    Board b = empty_board();
    for (int r=0; r<BOARDSIZE; r++) {
        for (int c=0; c<BOARDSIZE; c++) {
            switch (m) {
                case Up:
                    place(b, r, c, bget(og, c, BOARDSIZE-1-r));
                    break;
                case Down:
                    place(b, r, c, bget(og, BOARDSIZE-1-c, r));
                    break;
                case Left:
                    place(b, r, c, bget(og, r, BOARDSIZE-1-c));
                    break;
                case Right:
                    place(b, r, c, bget(og, r, c));
                    break;
                default:
                    break;
            }
        }
    }
    return b;
}
Exemplo n.º 25
0
/*
* mm_malloc - Allocate a block with at least size bytes of payload
* This function takes into account alignment and how the heap space
* is organized during any given malloc call.
*
* The adjusted block size is calculated by taking the max of the
* minimum size (24 bytes) and the requested size (aligned size + 8).
*
* It then searches the free list until it finds a place to put the block.
* Using this block pointer, it places the block in this spot.
*
* If no space was found, we must ask for more memory and then place at
* the block at the start of the new heap memory.
*
* This function takes a payload size as a parameter and returns
* a pointer to the start of the alocated block.
*/
void *mm_malloc(size_t size)
{
size_t asize; /* adjusted block size */
size_t extendsize; /* amount to extend heap if no fit */
char *bp;
/* Ignore spurious requests */
if (size <= 0)
return NULL;
/* Adjust block size to include overhead and alignment reqs */
asize = MAX(ALIGN(size) + DSIZE, MINIMUM);
/* Search the free list for a fit */
if ((bp = findFit(asize)))
{
place(bp, asize);
return bp;
}
/* No fit found. Get more memory and place the block */
extendsize = MAX(asize, CHUNKSIZE);
//return NULL if unable to get heap space
if ((bp = extendHeap(extendsize/WSIZE)) == NULL)
return NULL;
place(bp, asize);
return bp;
}
Exemplo n.º 26
0
/* 
 * mm_malloc - Allocate a block by incrementing the brk pointer.
 *     Always allocate a block whose size is a multiple of the alignment.
 */
void *mm_malloc(size_t size)
{
#ifdef __DEBUG__
	printf("Trying to allocate...\n");
#endif
	size_t adjSize;
	size_t extSize;
	void* bp;
	if(size == 0) return NULL;
	if(size<=DSIZE) adjSize = 3*DSIZE;
	else adjSize = DSIZE * ((size + 2*(DSIZE) + (DSIZE)-1) / DSIZE); //adjust size to align
	if((bp = find_fit(adjSize)) != NULL) { //is there any good place?
#ifdef __DEBUG__
		fprintf(stderr, "alloc ty 1 : %u\n",getBlockHeader(bp));
#endif
		return place(bp, adjSize);
	}
	extSize = MAX(adjSize, CHUNKSIZE); //f****d, extend heap and gather moar spaces
	if((bp = extend_heap(extSize/WSIZE)) == NULL) return NULL;
#ifdef __DEBUG__
	fprintf(stderr, "alloc ty 2 : %u\n",getBlockHeader(bp));
#endif
	return place(bp, adjSize);
}
Exemplo n.º 27
0
/*Dengan fungsi ini kita mencoba slot yang masih kosong berikutnya dan memeriksa posisi yang tepat dari Ratu */
void ratu(int baris, int n)
{
     int kolom;
     for(kolom=1;kolom<=n;kolom++)
     {
          if(place(baris,kolom))
          {
               papan[baris]=kolom;       // tidak ada konflik sehingga menempatkan ratu
               if(baris==n)               
               cetakpapan(n);          
               else                     // mencoba ratu dengan posisi berikutnya
               ratu(baris+1,n);
          }
     }
}
Exemplo n.º 28
0
/*
 * malloc
 */
void *malloc (size_t size) {
    checkheap(1);  // Let's make sure the heap is ok!
    size = size;

    size_t asize;      /* Adjusted block size */
    size_t extendsize; /* Amount to extend heap if no fit */
    char *bp;      

/* $end mmmalloc */
    if (heap_listp == 0){
    mm_init();
    }
/* $begin mmmalloc */
    /* Ignore spurious requests */
    if (size == 0)
    return NULL;

    /* Adjust block size to include overhead and alignment reqs. */
    if (size <= DSIZE)                                          //line:vm:mm:sizeadjust1
    asize = 2*DSIZE;                                        //line:vm:mm:sizeadjust2
    else
    asize = DSIZE * ((size + (DSIZE) + (DSIZE-1)) / DSIZE); //line:vm:mm:sizeadjust3

    /* Search the free list for a fit */
    if ((bp = find_fit(asize)) != NULL) {  //line:vm:mm:findfitcall
    place(bp, asize);                  //line:vm:mm:findfitplace
    return (void *)bp;
    }

    /* No fit found. Get more memory and place the block */
    extendsize = MAX(asize,CHUNKSIZE);                 //line:vm:mm:growheap1
    if ((bp = extend_heap(extendsize/WSIZE)) == NULL)  
    return NULL;                                  //line:vm:mm:growheap2
    place(bp, asize);                                 //line:vm:mm:growheap3
    return (void *)bp;
}
Exemplo n.º 29
0
void Board::reveal_around(Point loc)
{
	for (int idx = 0; idx < 3; idx++)
	{
		for (int indx = 0; indx < 3; indx++)
		{
			Point place(loc.x() + idx, loc.y() + indx);
			if (inBounds(place))
			{
				turnSpace(place);
			}

		}
	}
}
Exemplo n.º 30
0
/* 
 * Requires:
 *   None.
 *
 * Effects:
 *   Allocate a block with at least "size" bytes of payload, unless "size" is
 *   zero.  Returns the address of this block if the allocation was successful
 *   and NULL otherwise.
 */
void *
mm_malloc(size_t size) 
{
	size_t asize;      /* Adjusted block size */
	size_t extendsize; /* Amount to extend heap if no fit */
	void *bp;

	printf("Start malloc\n");
	/* Ignore spurious requests. */
	if (size == 0)
		return (NULL);

	/* Adjust block size to include overhead and alignment reqs. */
	/* Increased size to 4 words of overhead from 2 */
	/* Smallest useable block size is now 2 words instead of 1 */
	if (size <= ASIZE)
		asize = ASIZE + QSIZE;
	else
		asize = ASIZE * ((size + QSIZE + (ASIZE - 1)) / ASIZE);

	/* Search the free list for a fit. */
	if ((bp = find_fit(asize)) != NULL) {
		place(bp, asize);
		return (bp);
	}

	/* No fit found.  Get more memory and place the block. */
	extendsize = MAX(asize, CHUNKSIZE);
	if ((bp = extend_heap(extendsize / WSIZE)) == NULL)  
		return (NULL);

	place(bp, asize);
	checkheap(1);

	return (bp);
}