本文整理汇总了C++中Memory类的典型用法代码示例。如果您正苦于以下问题:C++ Memory类的具体用法?C++ Memory怎么用?C++ Memory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Memory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test
template<typename V, unsigned int Size> struct TestVectors2D { static void test()
{
typedef typename V::EntryType T;
const V startX(V::IndexType::IndexesFromZero() + Size);
Memory<V, Size, Size> m;
const Memory<V, Size, Size> &m2 = m;
V x = startX;
for (size_t i = 0; i < m.rowsCount(); ++i, x += V::Size) {
Memory<V, Size> &mrow = m[i];
for (size_t j = 0; j < mrow.vectorsCount(); ++j, x += V::Size) {
mrow.vector(j) = x;
}
}
x = startX;
for (size_t i = 0; i < m.rowsCount(); ++i, x += V::Size) {
Memory<V, Size> &mrow = m[i];
const Memory<V, Size> &m2row = m2[i];
size_t j;
for (j = 0; j < mrow.vectorsCount() - 1; ++j) {
COMPARE(V(mrow.vector(j)), x);
COMPARE(V(m2row.vector(j)), x);
for (int shift = 0; shift < V::Size; ++shift, ++x) {
COMPARE(V(mrow.vector(j, shift)), x);
COMPARE(V(m2row.vector(j, shift)), x);
}
}
COMPARE(V(mrow.vector(j)), x) << i << " " << j;
COMPARE(V(m2row.vector(j)), x);
x += V::Size;
}
}};
示例2: getVariable
bool WorkItem::printVariable(string name) const
{
// Find variable
const llvm::Value *value = getVariable(name);
if (!value)
{
return false;
}
// Get variable value
TypedValue result = getOperand(value);
const llvm::Type *type = value->getType();
if (value->getValueID() == llvm::Value::GlobalVariableVal ||
((const llvm::Instruction*)value)->getOpcode()
== llvm::Instruction::Alloca)
{
// If value is alloca or global variable, look-up data at address
size_t address = result.getPointer();
Memory *memory = getMemory(value->getType()->getPointerAddressSpace());
unsigned char *data = (unsigned char*)memory->getPointer(address);
printTypedData(value->getType()->getPointerElementType(), data);
}
else
{
printTypedData(type, result.data);
}
return true;
}
示例3: manageDrum
void manageDrum(int number) {
//IF THE DRUM ISNT BUSY AND THERES A RUNNINGJOB PASSED
if(!drum && number != -1) {
queueAllJobs();
//FIND WHERE THE JOB IS LOCATED IN THE MEMORY ARRAY
int jobPlaceInMem = memory.locateJob(jobs, number);
//CHECK MEMORY TO SEE IF THERE IS ENOUGH SPACE FOR THE JOB SIZE
//RETURNS THE # OF THE SPACE THAT IS FREE
int avail = memory.MemoryCheck(jobs[jobPlaceInMem].getSize());
//IF AVAIL < 100 AND IF THE JOB ISNT IN MEMORY
//PLACE THE LOCATION OF THE JOB IN THE AVAILABLE SPACE
//SWAP THE JOB INTO MEMORY (DRMINT WILL OCCUR)
//SET JOB GOING IN TO THE NUMBER OF THE JOB
//SET THE GOING DIRECTION
//SET THE JOB IN THE TABLE AND SET THE DRUM = TRUE
//WHEN TRUE IT MEANS THE DRUM IS BUSY
//tell the drmint that the drum is busy (use boolean or queue)
//TEST: [TRY USING queue.empty() OR bool drum = true]
if((avail < 100)){
if(!jobs[jobPlaceInMem].isInMemory()) {
drum = true;
jobGoingIn = number;
jobs[jobPlaceInMem].setLocation(avail);
memory.setMemory(jobs, jobPlaceInMem, avail);
siodrum(jobs[jobPlaceInMem].getNumber(), jobs[jobPlaceInMem].getSize(), jobs[jobPlaceInMem].getLocation(), 0);
}
}
}
}
示例4: catch
void Evaluator::overlap_check(bool throwOnErr)
{
Memory m;
Nodes & instructions = root->children;
for (auto i : instructions)
{
Nodes & lis = i->children;
for (auto l : lis )
{
Litem * pl = get<Litem>(LNFUN, l);
try
{
m.put(pl->address, pl->value);
}
catch (string e)
{
Err err("Memory overlap: " + pl->address.str(), pl->tok());
if (throwOnErr)
throw err;
else
std::cout << err.str() << '\n';
}
catch (...)
{
throw Err(LNFUN);
}
} // next litem
} // next instruction
}
示例5: DecryptEcb
//这个函数的特点是可以指定输入数据的长度,注意,input的有效数据长度必须是16的整数倍,input的大小必须大于等于len。
//但是outbuf仅仅存储,有效的输出长度。
int Aes::DecryptEcb(Memory<char>& outbuf,const void* input,int len){
if(len<=0) return 0;
if(outbuf.Length()<(uint)len){
if(!outbuf.SetLength(len)) return 0;
}
return DecryptEcb(outbuf.Handle(),len,input,len);
}
示例6:
MemoryReader::MemoryReader( Memory &source )
:curPos( 0 )
{
this->curData = source.GetData();
this->curLength = source.GetLength();
this->curPos = 0;
}//constructor
示例7: strToBoolean
BooleanValue strToBoolean (ConstMemory const value_mem)
{
if (value_mem.len() == 0)
return Boolean_Default;
// TODO malloc here is not necessary
Ref<String> value_str = grab (new String (value_mem));
Memory const mem = value_str->mem();
for (Size i = 0; i < mem.len(); ++i)
mem.mem() [i] = (Byte) tolower (mem.mem() [i]);
if (equal (mem, "y") ||
equal (mem, "yes") ||
equal (mem, "on") ||
equal (mem, "true") ||
equal (mem, "1"))
{
return Boolean_True;
}
if (equal (mem, "n") ||
equal (mem, "no") ||
equal (mem, "off") ||
equal (mem, "false") ||
equal (mem, "0"))
{
return Boolean_False;
}
return Boolean_Invalid;
}
示例8: load
bool load(std::istream &in, Memory& mem, addr_t img_base) {
if (virt_sz > 0) {
addr_t sect_addr_va = img_base + virt_addr;
int prot = get_prot(charac);
mem.alloc_protect(sect_addr_va , virt_sz, prot | Memory::Write);
//TODO check for file_sz > virt_sz (explained in spec)
if (file_sz > 0) {
std::istream::streampos pos_orig = in.tellg();
if (pos_orig == std::istream::pos_type(std::istream::off_type(-1)))
return false;
in.seekg(file_pos, std::ios_base::beg);
// TODO is "bad()" the right thing to check?
if (in.bad())
return false;
char *sect_data = new char[file_sz];
in.read(sect_data, file_sz);
if (std::size_t(in.gcount()) < file_sz) {
delete[] sect_data;
return false;
}
// perhaps change "write" interface to accept const char * to
// avoid this copying madness?
mem.write(sect_addr_va, std::string(sect_data, file_sz));
delete[] sect_data;
if (!(prot & Memory::Write))
mem.alloc_protect(sect_addr_va, virt_sz, prot);
in.seekg(pos_orig);
if (in.bad())
return false;
}
}
return true;
}
示例9: spawnWeapon
void spawnWeapon( LPVOID args ){
D3D9_item* item = (D3D9_item*) args;
Memory* m = (Memory*) item->arguments;
auto WeaponTable = WeaponTable::Singleton();
auto WeaponTableSize = WeaponTable->getTableSize();
auto world = World::Singleton();
auto locPlayer = world->getCameraOn()->getUnit();
auto InventoryTable = locPlayer->getInventoryTable();
auto InventoryTableSize = InventoryTable->getTableSize();
auto InventoryTableMaxSize = InventoryTable->getTableMaxSize();
auto Inventory = InventoryTable->getInventory( );
if( item->value > (int)(WeaponTableSize - 1) ){
item->value = 0;
item->isEnabled = false;
return;
}
auto Weapon = WeaponTable->getEntryById( item->value );
if( Weapon->getBase() ){
if( InventoryTableSize < InventoryTableMaxSize ){
DWORD distance = Inventory->calculateDistance( InventoryTableSize );
m->write( distance, Weapon->getBase() );
InventoryTable->setTableSize( InventoryTableSize + 1 );
weapons.push_back( distance );
}
}
item->isEnabled = false;
}
示例10: resizeArray
void Deque::resizeArray(Memory& mem, size_t newSize)
{
if(mDataLen == newSize)
return;
assert(newSize > mSize);
GCObject** newData = cast(GCObject**)mem.allocRaw(newSize * sizeof(GCObject*) MEMBERTYPEID);
if(mSize > 0)
{
if(mEnd > mStart)
memcpy(newData, mDataPtr + mStart, (mEnd - mStart) * sizeof(GCObject*));
else
{
size_t endLen = mDataLen - mStart;
memcpy(newData, mDataPtr + mStart, endLen * sizeof(GCObject*));
memcpy(newData + endLen, mDataPtr, mEnd * sizeof(GCObject*));
}
}
void* p = mDataPtr;
auto sz = mDataLen * sizeof(GCObject*);
mem.freeRaw(p, sz MEMBERTYPEID);
mDataPtr = newData;
mDataLen = newSize;
mStart = 0;
mEnd = mSize;
}
示例11: main
int main()
{
cout<<"Enter the algorithm number:"<<endl;
cout<<" 1) first_fit"<<endl;
cout<<" 2) best_fit"<<endl;
cout<<" 3) worst_fit"<<endl;
cin>>algorithm_mode;
HoleTable h1;
ProcessesTable t1;
Memory memory;
list<Node> list_processes;
holes_initialize(h1); //User Enter the holes (number of holes and the size of each one) all are handeled inside the function
/*
//Hard coded test case for holes input, make it easy in Debuging
h1.allocate(0,1);
h1.allocate(2,1);
h1.allocate(3,1);
h1.allocate(5,1);
h1.allocate(8,1);
h1.allocate(9,1);
*/
initial_Processes_table_filling(h1, t1, 10); //Automated function for entering initial processes, the name of these process is Px
memory.update_memory(h1,t1); //update the memory array
memory.print_memory_in_detail(); //Print the memory array in detail(name,base_address, size, final_addess)
input_processes(list_processes); //User enter the processes which he wants to allocate
tables_handler(list_processes,h1,t1,memory); //Handling algorithms after the user enters the processe,(for more details open the function)
cout<<endl<<"***************"<<" FINAL MEMORY "<<"*************"<<endl;
memory.update_memory(h1,t1); //final update for the memory array
memory.print_memory_in_detail(); //Print the memory array in detail
return 0;
}
示例12: it
Tribe::Memory* Tribe::FindRandomMemory(const char* name, const csVector3 &pos, const iSector* sector, float range, float* foundRange)
{
csArray<Memory*> nearby;
csArray<float> dist;
float minRange = range*range; // Working with Squared values
if(range == -1) minRange = -1; // -1*-1 = 1, will use -1 later
csList<Memory*>::Iterator it(memories);
while(it.HasNext())
{
Memory* memory = it.Next();
if(memory->name == name && memory->npc == NULL)
{
float dist2 = npcclient->GetWorld()->Distance(pos,sector,memory->pos,memory->GetSector());
if(minRange < 0 || dist2 < minRange)
{
nearby.Push(memory);
dist.Push(dist2);
}
}
}
if(nearby.GetSize()>0) // found one or more closer than range
{
size_t pick = psGetRandom((uint32)nearby.GetSize());
if(foundRange) *foundRange = sqrt(dist[pick]);
return nearby[pick];
}
return NULL;
}
示例13: main
int main(int argc, char *argv[])
{
Memory mr;
cout << "Enter a key number (write 0 to generate a random key): ";
int key;
cin>> key;
if(key<=0)
mr = Memory();
else
mr=Memory(key);
cout << "\nKey is:" <<mr.getKey();
char x;
while(1)
{
cout <<"\n\n-----------\nChoose one: \nr:Read\nd:Read with delay (to test concurrency)\nw:write\nx:exit\n-----------\n";
cin >> x;
if(x == 'r')
{
cout << "Data is: "<<mr.read();
}
else if(x == 'd')
{
cout << "Data is: "<<mr.read(8);
}
else if(x == 'w')
{
string s;
cout << "Enter data to input: ";
cin >> s;
mr.write(s);
}
else if(x == 'x')
示例14: 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;
}
示例15: alGetSourcei
bool StreamedInstance::Update()
{
if (mState != State::Playing) return false;
int queued;
alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
ASSERT(alGetError() == 0, "AL error occured");
if (queued)
{
int processed;
alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
ASSERT(alGetError() == 0, "AL error occured");
while (processed--)
{
uint processedBuffer;
alSourceUnqueueBuffers(mSource, 1, &processedBuffer);
ASSERT(alGetError() == 0, "AL error occured");
if (((StreamedSound*)mSound)->GetAudioData()->IsEOF() && mRepeat)
{
((StreamedSound*)mSound)->GetAudioData()->Reset();
}
if (!((StreamedSound*)mSound)->GetAudioData()->IsEOF())
{
Memory dataOut;
ALenum format = (((StreamedSound*)mSound)->GetAudioData()->GetChannels() == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
((StreamedSound*)mSound)->GetAudioData()->Decode(dataOut);
alBufferData(processedBuffer, format, dataOut.GetBuffer(), dataOut.GetSize(), ((StreamedSound*)mSound)->GetAudioData()->GetRate());
ASSERT(alGetError() == 0, "AL error occured");
alSourceQueueBuffers(mSource, 1, &processedBuffer);
ASSERT(alGetError() == 0, "AL error occured");
}
}
int streamState;
alGetSourcei(mSource, AL_SOURCE_STATE, &streamState);
if (streamState == AL_STOPPED)
{
alSourcePlay(mSource);
}
return true;
}
else
{
// Load the buffers with initial data in case the sound is to be played again.
Init();
mState = State::Stopped;
mActiveInstancesEntry = NULL;
return false;
}
}