public Result allocate(String type, int n) throws IOException {
		ArrayList<ByteBuffer> bufs = new ArrayList<ByteBuffer>(n);
		
		long start = System.currentTimeMillis();
		
		if (type.equalsIgnoreCase("onheap"))
		{
			for (int i = 0; i < n; i++) // 1200*1M to produce OOM with a 1G heap
			{
				ByteBuffer bb = ByteBuffer.allocate(1024*1024);
				bufs.add(bb);
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		else if (type.equalsIgnoreCase("offheap"))
		{
			for (int i = 0; i < n; i++)
			{
				ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024);
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				bufs.add(bb);
			}
		}
		
		long end = System.currentTimeMillis();
		System.out.printf("Cost %d ms\n", end-start);
		
		for(ByteBuffer bb : bufs)
		{
			destroyDirectBuffer(bb);
		}
		bufs.clear();
		//System.gc();
		return new Result(n, (int) (end-start));
	}