void* BMMS::_mallocBMMS(unsigned int reqSize) { int pos,blocksRequired; blocksRequired = divCeil(reqSize,blockSize); #ifdef _DEBUG cerr<<"BMMS::malloc["<<reqSize<<"]"<<endl<<"num of blocks:"<<numOfBlocks<<", Block size:"<<blockSize<<"-> Required("<<reqSize<<"): "<<blocksRequired<<endl; #endif pos = findAndAssignPortion(blocksRequired); #ifdef _DEBUG cerr<<"num of blocks:"<<numOfBlocks<<", Block size:"<<blockSize<<"-> Required("<<reqSize<<"): "<<blocksRequired<<endl; cerr<<"Allocato en ["<<pos<<"]"<<endl; fprintf(stderr,"[%d] -> %p\n",pos,allocatedMemory+(pos*blockSize)); #endif if(pos==-1){ cerr<<"BMMS->WARN:Not enough memory or could not allocate(frag.):"<<reqSize<<"bytes"<<endl; return NULL; }else{ return (void*)(allocatedMemory+(pos*blockSize)); } }
inline int_tt roundUp(int_tt val, int_tt factor) { return divCeil(val, factor) * factor ; }