本文整理汇总了C++中MemoryManager::checkMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryManager::checkMemory方法的具体用法?C++ MemoryManager::checkMemory怎么用?C++ MemoryManager::checkMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryManager
的用法示例。
在下文中一共展示了MemoryManager::checkMemory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f_parallel_for_array
// f_parallel_for
// begin - start of range to process
// end - 1 after end of range to process
// func - worker function of the form worker($begin, $end, $inputdata) - returns an array of max length ($end-$begin)
// blocksize - optional blocksize, refer to TBB documentation
// Returns: array of maximum length ($end-$begin)
//
// Call 'func' for non-overlapping array segments to cover all of arraydata
// This will use threads as appropriate for the machine.
// If a result is returned by 'func' it will be placed into the result array elements corresponding to the input elements
Variant f_parallel_for_array(CVarRef arraydata, CVarRef func, int64 blocksize /* = -1 */) {
if(!arraydata.isArray())
{
raise_error("parallel_for_array expected an array in first argument");
return Variant();
}
// Get the input array
const Array aArray = arraydata.asCArrRef();
ArrayData *pdArray = aArray.getArrayData();
size_t asize = pdArray->size();
if(asize==0)
return Variant();
MemoryManager *mm = MemoryManager::TheMemoryManager().get();
if (RuntimeOption::CheckMemory) {
mm->checkMemory(false);
}
TbbContext myContext = TbbContext::Entry("parallel_for_array");
std::vector<Variant> outArray;
outArray.resize(asize);
// Construct task parameters
PforTaskParameters tclass = PforTaskParameters(myContext, pdArray, func, &outArray);
TbbInitializeIfNeeded();
if (blocksize == -1) {
// Use auto_partitioner for block size
tbb::parallel_for(tbb::blocked_range<int64>(0, asize), tclass, tbb::auto_partitioner());
} else {
// Use manually set block size
tbb::parallel_for(tbb::blocked_range<int64>(0, asize, blocksize), tclass);
}
myContext.Exit();
// Create the result array
Array resPHPArray = Array::Create();
for(size_t ai=0; ai<outArray.size(); ai++) {
Variant amem = outArray[ai];
// printf(" ai=%d, append %s\n", (int)ai, amem.toString().c_str());
if(!amem.isNull())
resPHPArray.append(amem);
}
if(resPHPArray.size()==0)
return Variant(); // i.e null
return resPHPArray.getArrayData();
}