コード例 #1
0
ファイル: mm.c プロジェクト: YurieCo/hsi
/* Allocate a block of size size and return a pointer to it. */
void* mm_malloc (size_t size) 
{
  size_t reqSize;
  BlockInfo * ptrFreeBlock = NULL, * head;
  size_t blockSize;
  size_t precedingBlockUseTag;
  size_t extendsize; /* Amount to extend heap if no fit */

  // Zero-size requests get NULL.
  if (size == 0) {
    return NULL;
  }

  // Add one word for the initial size header.
  // Note that we don't need to boundary tag when the block is used!
  size += WORD_SIZE;
  if (size <= MIN_BLOCK_SIZE) {
    // Make sure we allocate enough space for a blockInfo in case we
    // free this block (when we free this block, we'll need to use the
    // next pointer, the prev pointer, and the boundary tag).
    reqSize = MIN_BLOCK_SIZE;
  } 
  else {
    // Round up for correct alignment
    reqSize = ALIGNMENT * ((size + ALIGNMENT - 1) / ALIGNMENT);
  }

  // Implement mm_malloc.  You can change or remove any of the above
  // code.  It is included as a suggestion of where to start.
  // You will want to replace this return statement...
  
  //head = FREE_LIST_HEAD;
  //printf("\nSo we were requested %d (%d). Free list head was 0x%x %d 0x%x 0x%x\n",
  //			 size, reqSize, head, head->sizeAndTags, head->next, head->prev );
  			 
  // half-arsed fix
	reqSize=reqSize+ALIGNMENT;
	
  if ( ptrFreeBlock = searchFreeList(reqSize) )
  {
  	precedingBlockUseTag = ptrFreeBlock->sizeAndTags & TAG_PRECEDING_USED;
  	placeBlock( ptrFreeBlock, reqSize, precedingBlockUseTag );  	
  }
  
  else
  {
  	//printf("But there wasn't big enough free block, we requsted extension %d\n", extendsize);
  	requestMoreSpace( reqSize );
  	ptrFreeBlock = searchFreeList(reqSize);
  	//printf("We got ourselves new pointer to free block after 0x%x %d 0x%x 0x%x\n", 
  	//				(int*)ptrFreeBlock, (int)ptrFreeBlock->sizeAndTags, (int*)ptrFreeBlock->next, (int*)ptrFreeBlock->prev);
  	precedingBlockUseTag = TAG_PRECEDING_USED;
  	placeBlock( ptrFreeBlock, reqSize, precedingBlockUseTag );
  }  
    
	return ((void*) POINTER_ADD(ptrFreeBlock, WORD_SIZE)); 
}
コード例 #2
0
ファイル: mm.c プロジェクト: caweinshenker/CS304
/* Allocate a block of size size and return a pointer to it. */
void * mm_malloc (size_t size) {
  size_t reqSize;
  BlockInfo * ptrFreeBlock = NULL;
  //Zero-size requests get NULL;
  if (size == 0){
    return NULL;
  }
  //Add one word for the initial size header.
  //Note that we don't need to boundary tag when the block is used!
  if (size <= MIN_BLOCK_SIZE) {
   // Make sure we allocate enough space for a blockInfo in case we
   // free this block (when we free this block, we'll need to use the
   // next pointer, the prev pointer, and the boundary tag).
   reqSize = MIN_BLOCK_SIZE;
 } else {
   // Round up for correct alignment
   reqSize = ALIGNMENT * ((size + ALIGNMENT - 1) / ALIGNMENT);
 }
  printf("Begin malloc of reqSize: %zd \n", reqSize);
  printf("Free list head: %p\n", FREE_LIST_HEAD);
  examine_heap();
  while ((ptrFreeBlock = searchFreeList(reqSize)) == NULL){
    requestMoreSpace(reqSize);
    printf("Finished space request\n");
  }
  removeFreeBlock(ptrFreeBlock);
  placeBlock(ptrFreeBlock, reqSize);
  printf("Completed malloc\n");
  printf("Pointer free block: %p\n", ptrFreeBlock);
  examine_heap();
  return UNSCALED_POINTER_ADD(ptrFreeBlock, WORD_SIZE);
}
コード例 #3
0
task main()
{
	waitForStart();
	wait1Msec(8000);
	//ClearTimer(T1);
	alignWithBeacon();
	//ClearTimer(T1);
	placeBlock();
	parkOnBridge();
}
コード例 #4
0
task main()
{
	initializeRobot();
	waitForStart();
	//ClearTimer(T1);
	alignWithBeacon();
	//ClearTimer(T1);
	placeBlock();
	parkOnBridge();
}
コード例 #5
0
// ///////////////////SET Block Objects/////////////////////////////////////////////
void LvlScene::setBlocks(QProgressDialog &progress)
{
    int i=0;

    //Applay images to objects
    for(i=0; i<LvlData->blocks.size(); i++)
    {
        //Add block to scene
        placeBlock(LvlData->blocks[i]);

        if(progress.wasCanceled())
            //progress.setValue(progress.value()+1);
        /*else*/ return;
    }
}
コード例 #6
0
ファイル: Left_Auto.c プロジェクト: coder-bot/ftc5602-code
task main ()
{
	initializeRobot();
	waitForStart();

	if (STARTING_SIDE == LEFT_SIDE) {
		leftScanForBeacon();
	}
	else if (STARTING_SIDE == RIGHT_SIDE) {
		rightScanForBeacon();
	}
	if (SensorValue [irSensor] != 4)
	{
		alignWithBeacon();
	}
	driveToBeacon(38);
	placeBlock();
#if 0
	driveOntoRamp();
#endif
}
コード例 #7
0
ファイル: FB_IR.c プロジェクト: coder-bot/ftc5602-code
task main()
{
    initializeRobot();
    waitForStart();
    //drive(0, 100, 0);
    //wait1Msec(1000);
    while (SensorValue [sonarSensor] > blockPlacementDist)
    {
        if (SensorValue [irSensor] < 5) {
            drive(-50, 50, 0);
        }
        else if (SensorValue [irSensor] > 5) {
            drive(50, 50, 0);
        }
        else if (SensorValue [irSensor] == 5) {
            drive(0, 50, 0);
        }
    }
    allStop();
    placeBlock();
}
コード例 #8
0
ファイル: kmagnetgenerator.cpp プロジェクト: omllobet/kmagnet
/* puts a new block in the board*/
bool kmagnetGenerator::newBlock(int currentpos, Moves::Move m)
{
    QVector<int> u,d,l,r;
    int toadd=0;
    int pos=0;
    if (m==Moves::UP)
    {
        toadd=currentpos-2*columns;
        pos=currentpos-columns;
        if (pos>=0 && !m_scene->getCell(pos)->getIsFree()) toadd=-1;//ugly
        while (toadd>=0 && m_scene->getCell(toadd)->getIsFree())
        {
            if (!forbiddenPos.contains(toadd)) {
                u.append(toadd);
            }
            toadd=toadd-columns;
        }
        return placeBlock(u, m);
    }
    else if (m==Moves::DOWN)
    {
        toadd=currentpos+2*columns;
        pos=currentpos+columns;
        if (pos <numcells && !m_scene->getCell(pos)->getIsFree()) toadd=numcells;
        while (toadd<numcells && m_scene->getCell(toadd)->getIsFree())
        {
            if (!forbiddenPos.contains(toadd)) {
                d.append(toadd);
            }
            toadd=toadd+columns;
        }
        return placeBlock(d, m);
    }
    else if (m==Moves::LEFT)
    {
        toadd=currentpos+2;
        int endr=( currentpos/columns ) *columns+columns;
        pos=currentpos+1;
        if (pos < numcells && !m_scene->getCell(pos)->getIsFree()) toadd=endr;
        while (toadd<endr && m_scene->getCell(toadd)->getIsFree())
        {
            if (!forbiddenPos.contains(toadd)) {
                r.append(toadd);
            }
            toadd++;
        }
        return placeBlock(r, m);
    }
    else if (Moves::RIGHT)
    {
        toadd=currentpos-2;
        int endl=static_cast<int> ( ( currentpos/columns ) *columns );
        pos=currentpos-1;
        if (pos >=0 && !m_scene->getCell(pos)->getIsFree()) toadd=endl-1;
        while (toadd>=endl && m_scene->getCell(toadd)->getIsFree())
        {
            if (!forbiddenPos.contains(toadd)) {
                l.append(toadd);
            }
            toadd--;
        }
        return placeBlock(l, m);
    }
    return true;
}