Beispiel #1
0
		String StringParser::getword() {
			// Should ignore , . ! " etc.
			return getbefore(" ");
		}
Beispiel #2
0
void myfree(void *memory_block) 
{
	if(memory_block== NULL)
	{
		return;
	}
	int * memtemp = (int*) memory_block;//header of to be freed block
	memtemp = (memtemp-2);
	int * freetemp = freelist;

	if (freelist == NULL)
	{
		freelist = memtemp;
	}
	else if (freetemp > memtemp) // allocated block is before the start of free list
	{
		int dif = (freelist - memtemp)*4;
		*(memtemp+1) = dif;//set next
		freelist = memtemp;
	}
	else
	{

		while (((freetemp + (*(freetemp+1))/4)< memtemp) && (*(freetemp + 1) != 0)) //while freelist is before to be freed and not in last spot
		{
			freetemp = freetemp + (*(freetemp+1))/4;
		}
		//should be at free block before our to be freed block
		if (*(freetemp+1)!= 0)
		{
			int dif = (memtemp - freetemp)*4;
			*(memtemp+1) = *(freetemp+1) - dif;
			*(freetemp+1) = dif;//set next
		}
		else//last of freelist
		{
			int dif = (memtemp - freetemp)*4;
			*(freetemp+1) = dif;//set next
		}
		
	}
	while(1)  //merging of blocks
	{
		int *before = getbefore(memtemp);
		if(checkbuddy(before, memtemp)) //previous is buddy?
		{
			memtemp = merge(before, memtemp);
		}
		else if(*(memtemp+0) == *(memtemp+1)) //if size = next, then neighbor in freelist so we can check the right block
		{
			if(checkbuddy(memtemp + (*(memtemp+0)/4), memtemp))
			{
				memtemp = merge(memtemp, memtemp + (*(memtemp+0)/4));
			}		
			else
			{
				return;
			}
		}
		else
		{
			return;  //no buddies!
		}
	}
}