30 lines
		
	
	
		
			638 B
		
	
	
	
		
			C++
		
	
	
		
		
			
		
	
	
			30 lines
		
	
	
		
			638 B
		
	
	
	
		
			C++
		
	
	
| 
								 | 
							
								namespace factor
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * It is up to the caller to fill in the object's fields in a meaningful
							 | 
						||
| 
								 | 
							
								 * fashion!
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								inline object *factor_vm::allot_object(header header, cell size)
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
									/* If the object is smaller than the nursery, allocate it in the nursery,
							 | 
						||
| 
								 | 
							
									after a GC if needed */
							 | 
						||
| 
								 | 
							
									if(nursery.size > size)
							 | 
						||
| 
								 | 
							
									{
							 | 
						||
| 
								 | 
							
										/* If there is insufficient room, collect the nursery */
							 | 
						||
| 
								 | 
							
										if(nursery.here + size > nursery.end)
							 | 
						||
| 
								 | 
							
											primitive_minor_gc();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										object *obj = nursery.allot(size);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										obj->h = header;
							 | 
						||
| 
								 | 
							
										return obj;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									/* If the object is bigger than the nursery, allocate it in
							 | 
						||
| 
								 | 
							
									tenured space */
							 | 
						||
| 
								 | 
							
									else
							 | 
						||
| 
								 | 
							
										return allot_large_object(header,size);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 |