deps/jemalloc/src/chunk.c
/*
 * If the caller specifies (*zero == false), it is still possible to receive
 * zeroed memory, in which case *zero is toggled to true.  arena_chunk_alloc()
 * takes advantage of this to avoid demanding zeroed chunks, but taking
 * advantage of them if they are returned.
 */
If the caller specifies (*zero == false), it is still possible to receive
zeroed memory, in which case *zero is toggled to true.  arena_chunk_alloc()
takes advantage of this to avoid demanding zeroed chunks, but taking
advantage of them if they are returned.
If the caller specifies ( * zero == false ) it is still possible to receive zeroed memory in which case * zero is toggled to true . arena_chunk_alloc () takes advantage of this to avoid demanding zeroed chunks but taking advantage of them if they are returned .
void *
chunk_alloc(size_t size, size_t alignment, bool base, bool *zero)
{
	void *ret;
	assert(size != 0);
	assert((size & chunksize_mask) == 0);
	assert(alignment != 0);
	assert((alignment & chunksize_mask) == 0);
	ret = chunk_recycle(size, alignment, base, zero);
	if (ret != NULL)
		goto label_return;
	ret = chunk_alloc_mmap(size, alignment, zero);
	if (ret != NULL)
		goto label_return;
	if (config_dss) {
		ret = chunk_alloc_dss(size, alignment, zero);
		if (ret != NULL)
			goto label_return;
	}
	ret = NULL;
label_return:
	if (config_ivsalloc && base == false && ret != NULL) {
		if (rtree_set(chunks_rtree, (uintptr_t)ret, ret)) {
			chunk_dealloc(ret, size, true);
			return (NULL);
		}
	}
	if ((config_stats || config_prof) && ret != NULL) {
		bool gdump;
		malloc_mutex_lock(&chunks_mtx);
		if (config_stats)
			stats_chunks.nchunks += (size / chunksize);
		stats_chunks.curchunks += (size / chunksize);
		if (stats_chunks.curchunks > stats_chunks.highchunks) {
			stats_chunks.highchunks = stats_chunks.curchunks;
			if (config_prof)
				gdump = true;
		} else if (config_prof)
			gdump = false;
		malloc_mutex_unlock(&chunks_mtx);
		if (config_prof && opt_prof && opt_prof_gdump && gdump)
			prof_gdump();
	}
	if (config_debug && *zero && ret != NULL) {
		size_t i;
		size_t *p = (size_t *)(uintptr_t)ret;
		VALGRIND_MAKE_MEM_DEFINED(ret, size);
		for (i = 0; i < size / sizeof(size_t); i++)
			assert(p[i] == 0);
	}
	assert(CHUNK_ADDR2BASE(ret) == ret);
	return (ret);
}
void * chunk_alloc ( size_t size , size_t alignment , bool base , bool * zero ) { void * ret ; assert ( size != 0 ) ; assert ( ( size & chunksize_mask ) == 0 ) ; assert ( alignment != 0 ) ; assert ( ( alignment & chunksize_mask ) == 0 ) ; ret = chunk_recycle ( size , alignment , base , zero ) ; if ( ret != NULL ) goto label_return ; ret = chunk_alloc_mmap ( size , alignment , zero ) ; if ( ret != NULL ) goto label_return ; if ( config_dss ) { ret = chunk_alloc_dss ( size , alignment , zero ) ; if ( ret != NULL ) goto label_return ; } ret = NULL ; label_return : if ( config_ivsalloc && base == false && ret != NULL ) { if ( rtree_set ( chunks_rtree , ( uintptr_t ) ret , ret ) ) { chunk_dealloc ( ret , size , true ) ; return ( NULL ) ; } } if ( ( config_stats || config_prof ) && ret != NULL ) { bool gdump ; malloc_mutex_lock ( & chunks_mtx ) ; if ( config_stats ) stats_chunks . nchunks += ( size / chunksize ) ; stats_chunks . curchunks += ( size / chunksize ) ; if ( stats_chunks . curchunks > stats_chunks . highchunks ) { stats_chunks . highchunks = stats_chunks . curchunks ; if ( config_prof ) gdump = true ; } else if ( config_prof ) gdump = false ; malloc_mutex_unlock ( & chunks_mtx ) ; if ( config_prof && opt_prof && opt_prof_gdump && gdump ) prof_gdump ( ) ; } if ( config_debug && * zero && ret != NULL ) { size_t i ; size_t * p = ( size_t * ) ( uintptr_t ) ret ; VALGRIND_MAKE_MEM_DEFINED ( ret , size ) ; for ( i = 0 ; i < size / sizeof ( size_t ) ; i ++ ) assert ( p [ i ] == 0 ) ; } assert ( CHUNK_ADDR2BASE ( ret ) == ret ) ; return ( ret ) ; }
If the caller specifies (*zero == false), it is still possible to receive
 zeroed memory, in which case *zero is toggled to true.
If the caller specifies ( * zero == false ) it is still possible to receive zeroed memory in which case * zero is toggled to true .
/* All strategies for allocation failed. */