src/backend/utils/sort/logtape.c
/*
 * Create a set of logical tapes in a temporary underlying file.
 *
 * Each tape is initialized in write state.
 */
Create a set of logical tapes in a temporary underlying file.
Each tape is initialized in write state.
Create a set of logical tapes in a temporary underlying file . Each tape is initialized in write state .
LogicalTapeSet *
LogicalTapeSetCreate(int ntapes)
{
	LogicalTapeSet *lts;
	LogicalTape *lt;
	int			i;
	Assert(ntapes > 0);
	lts = (LogicalTapeSet *) palloc(offsetof(LogicalTapeSet, tapes) +
									ntapes * sizeof(LogicalTape));
	lts->pfile = BufFileCreateTemp(false);
	lts->nFileBlocks = 0L;
	lts->forgetFreeSpace = false;
	lts->blocksSorted = true;	
	lts->freeBlocksLen = 32;	
	lts->freeBlocks = (long *) palloc(lts->freeBlocksLen * sizeof(long));
	lts->nFreeBlocks = 0;
	lts->nTapes = ntapes;
	for (i = 0; i < ntapes; i++)
	{
		lt = &lts->tapes[i];
		lt->indirect = NULL;
		lt->writing = true;
		lt->frozen = false;
		lt->dirty = false;
		lt->numFullBlocks = 0L;
		lt->lastBlockBytes = 0;
		lt->buffer = NULL;
		lt->buffer_size = 0;
		lt->curBlockNumber = 0L;
		lt->pos = 0;
		lt->nbytes = 0;
	}
	return lts;
}
LogicalTapeSet * LogicalTapeSetCreate ( int ntapes ) { LogicalTapeSet * lts ; LogicalTape * lt ; int i ; Assert ( ntapes > 0 ) ; lts = ( LogicalTapeSet * ) palloc ( offsetof ( LogicalTapeSet , tapes ) + ntapes * sizeof ( LogicalTape ) ) ; lts -> pfile = BufFileCreateTemp ( false ) ; lts -> nFileBlocks = 0L ; lts -> forgetFreeSpace = false ; lts -> blocksSorted = true ; lts -> freeBlocksLen = 32 ; lts -> freeBlocks = ( long * ) palloc ( lts -> freeBlocksLen * sizeof ( long ) ) ; lts -> nFreeBlocks = 0 ; lts -> nTapes = ntapes ; for ( i = 0 ; i < ntapes ; i ++ ) { lt = & lts -> tapes [ i ] ; lt -> indirect = NULL ; lt -> writing = true ; lt -> frozen = false ; lt -> dirty = false ; lt -> numFullBlocks = 0L ; lt -> lastBlockBytes = 0 ; lt -> buffer = NULL ; lt -> buffer_size = 0 ; lt -> curBlockNumber = 0L ; lt -> pos = 0 ; lt -> nbytes = 0 ; } return lts ; }
Create a set of logical tapes in a temporary underlying file.
Create a set of logical tapes in a temporary underlying file .
/*
	 * Create top-level struct including per-tape LogicalTape structs.
	 */ /* a zero-length array is sorted ... */ /* reasonable initial guess */ /*
	 * Initialize per-tape structs.  Note we allocate the I/O buffer and
	 * first-level indirect block for a tape only when it is first actually
	 * written to.  This avoids wasting memory space when tuplesort.c
	 * overestimates the number of tapes needed.
	 */