Esempio n. 1
0
void*
kma_malloc(kma_size_t size)
{       
   /* size + header size larger than page size, do nothing and return null */
   if ((size + BLKHDR) > PAGESIZE) return NULL;
   
   /* if master page is not set up, call kma_init */
   if (master == NULL) { 
	kma_init();	
   }
   
   /* find the page to insert */ 
   void* block = kma_find_block(size);
   
   //remove the block from freelist
   fl_remove(block);

   /* split the blocks */
   void* alloc = kma_split(block, size);

   return alloc + BLKHDR;
}
Esempio n. 2
0
File: kma.c Progetto: acceso/jOS
int
main (int argc, char **argv)
{
	void *a, *b, *c, *d;

	kma_init ();

	a = _kma_alloc (17*KB);
	b = _kma_alloc (34*KB);
	c = _kma_alloc (2*MB);
	d = _kma_alloc (1*MB);

	_kma_free (d);
	_kma_free (a);
	_kma_free (c);
	_kma_free (b);

	a = _kma_alloc (17*KB);
	_kma_free (a);

	return 0;
}