本文整理汇总了C++中Memory::allocateMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ Memory::allocateMemory方法的具体用法?C++ Memory::allocateMemory怎么用?C++ Memory::allocateMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memory
的用法示例。
在下文中一共展示了Memory::allocateMemory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spawnAmmunation
void spawnAmmunation( LPVOID args ){
D3D9_item* item = (D3D9_item*) args;
Memory* m = (Memory*) item->arguments;
auto ConsumableTable = ConsumableTable::Singleton();
auto ConsumableTableSize = ConsumableTable->getTableSize();
auto world = World::Singleton();
auto locPlayer = world->getCameraOn()->getUnit();
auto InventoryTable = locPlayer->getInventoryTable();
auto InventoryTableSize = InventoryTable->getConsumableTableSize();
auto InventoryTableMaxSize = InventoryTable->getConsumableTableMaxSize( );
auto Inventory = InventoryTable->getConsumableInventory();
if( item->value > (int)(ConsumableTableSize - 1) ){
item->value = 0;
item->isEnabled = false;
return;
}
auto Consumable = ConsumableTable->getEntryById( item->value );
if( Consumable->getBase() ){
if( InventoryTableSize < InventoryTableMaxSize ){
DWORD memory = m->allocateMemory( 0x2C );
if (!memory) {
console->sendInput( "Failed to allocate memory!" );
return;
}
DWORD item1 = m->read<DWORD>( m->read<DWORD>( Inventory->getBase( ) + 0x28 ) );
DWORD item2 = m->read<DWORD>( m->read<DWORD>( Inventory->getBase( ) + 0x4 ) );
m->write( memory, m->read<DWORD>( Inventory->getBase() ) );
m->write( memory + 0x4, item2 );
m->write( memory + 0x8, Consumable->getBase() );
m->write( memory + 0x28, item1 );
m->write( memory + 0x2C, itemRef );
itemRef++;
/* UNCHECKED */
int ammoXOR = m->read<DWORD>( Consumable->getBase() + 0x2C ) ^ (int)( 0xBABAC8B6L );
int ammoVal = ammoXOR << 1;
m->write( memory + 0xC, int( ammoXOR - ammoVal ) );
m->write( memory + 0x24, ammoVal );
/* END UNCHECKED */
DWORD distance = Inventory->calculateDistance( InventoryTableSize );
m->write( distance, memory );
InventoryTable->setConsumableTableSize( InventoryTableSize + 1 );
}
}
item->isEnabled = false;
}
示例2: main
int main(){
vector<pair<int,int>>holes;
int numHoles=0;
while(numHoles<=0){
cout<<"Enter number of holes: ";
cin>>numHoles;
if(numHoles<=0)
cout<<"Number of holes must be > 0\n";
else break;
}
int holeStart,holeSize;
for(int i=0;i<numHoles;i++){
cout<<"Enter hole starting position and hole size: ";
cin>>holeStart>>holeSize;
if(holeStart<0){cout<<"start can't be negative"<<endl;i--;continue;}
if(holeSize<0){cout<<"size can't be negative"<<endl;i--;continue;}
holes.push_back({holeStart,holeSize});
}
sort(holes.begin(),holes.end());
int j=0;
vector<pair<int,int>>merged_holes;
for(int i=0;i<holes.size();i=j){
for(j=i+1;j<holes.size();j++){
if(holes[i].first+holes[i].second>=holes[j].first){
holes[i].second=max(holes[i].first+holes[i].second,holes[j].first+holes[j].second)-holes[i].first;
}
else break;
}
merged_holes.push_back({holes[i].first,holes[i].second});
}
vector<Block*>initial_blocks;
int process_counter=-1;
if(merged_holes[0].first!=0){
initial_blocks.push_back(new Process(process_counter,0,merged_holes[0].first));
}
for(int i=0;i<merged_holes.size();i++){
initial_blocks.push_back(new Block(merged_holes[i].first,merged_holes[i].second));
if(i==merged_holes.size()-1)break;
initial_blocks.push_back(new Process(process_counter,merged_holes[i].first+merged_holes[i].second,merged_holes[i+1].first-(merged_holes[i].first+merged_holes[i].second)));
}
Memory *memory;
int type;
cout<<"Enter the type of the memory (1- First Fit, 2-Best Fit, 3-Worst Fit): ";
cin>>type;
if(type==1){
memory = new FirstFitMemory(initial_blocks);
}else if(type==2){
memory = new BestFitMemory(initial_blocks);
}else if(type==3){
memory = new WorstFitMemory(initial_blocks);
}else{
cout<<"Type is invalid.";
return 0;
}
cout<<"Memory was successfully created"<<endl;
memory->print();
int id,limit;
for(;;){
int query_type;
cout<<"Enter the query type (1- Allocate, 2- Deallocate, 3- Finish): ";
cin>>query_type;
if(query_type==1){
cout<<"Enter the id of the process: ";
cin>>id;
cout<<"Enter the size of the process: ";
cin>>limit;
if(memory->allocateMemory(id,limit)){
cout<<"The Process was successfully allocated"<<endl;
memory->print();
}
else{
cout<<"No enough space to add the process"<<endl;
}
}else if(query_type==2){