本文整理汇总了C++中Arena类的典型用法代码示例。如果您正苦于以下问题:C++ Arena类的具体用法?C++ Arena怎么用?C++ Arena使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arena类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defense
/*********************************************************************************
*Description - Defense fn
*fn that send number of die and faces to Arena class and assesses the amount of
*damage received
*Parameters - Passes the amount of damage received to the the Armor fn, using
polymorphism
*********************************************************************************/
void Reptile::defense() {
int defend, damage, impact;
battle3.setNumFaces(R_DEFEND_FACE);
battle3.setNumDice(R_DEFEND_DIE);
defend = battle3.Roll();
battle3.setDefendRoll(defend);
damage = battle3.deathBlow();
if(damage == 0)
{
cout << "No damage!!" << endl;
}
else if(damage > R_ARMOR)
{
impact = damage - R_ARMOR;
cout << "The Reptile People were injured! Because of armor, it only had an impact of: -"<< impact << endl;
}
else if((damage > 0) && (damage <= R_ARMOR))
{
cout << "The Reptile People were hit, but were saved by their armor!!" << endl;
}
Character *chr = &rep;
chr->armor(damage);
chr->strength();
}
示例2: cmd
Battle::Command Battle::Catapult::GetCommand(Arena & arena) const
{
u32 shots = cat_shots;
std::vector<u32> values(CAT_MISS + 1, 0);
values[CAT_WALL1] = arena.GetCastleTargetValue(CAT_WALL1);
values[CAT_WALL2] = arena.GetCastleTargetValue(CAT_WALL2);
values[CAT_WALL3] = arena.GetCastleTargetValue(CAT_WALL3);
values[CAT_WALL4] = arena.GetCastleTargetValue(CAT_WALL4);
values[CAT_TOWER1] = arena.GetCastleTargetValue(CAT_TOWER1);
values[CAT_TOWER2] = arena.GetCastleTargetValue(CAT_TOWER2);
values[CAT_TOWER3] = arena.GetCastleTargetValue(CAT_TOWER3);
values[CAT_BRIDGE] = arena.GetCastleTargetValue(CAT_BRIDGE);
Command cmd(MSG_BATTLE_CATAPULT);
cmd.GetStream() << shots;
while(shots--)
{
int target = GetTarget(values);
u32 damage = GetDamage(target, arena.GetCastleTargetValue(target));
cmd.GetStream() << target << damage;
values[target] -= damage;
}
return cmd;
}
示例3: main
int main()
{
Comparator cmp;
Arena arena;
SkipList<Key, Comparator> list(cmp, &arena);
const int N = 2000;
std::set<Key> keys;
for (int i = 0; i < N; i++)
{
list.Insert(i);
keys.insert(i);
}
for (auto it = keys.begin(); it != keys.end(); ++it)
{
if (!list.Contains(*it))
{
cout<<*it<<"\t";
}
}
size_t * p = (size_t*)(arena.AllocateAligned(sizeof(size_t)));
*p = 100;
cout<<*p<<endl;
list.NewNodeTest(100, 12);
return 0;
}
示例4: main
int main(int argc, char** argv) {
srand(time(NULL));
Arena<Fighter *> arena;
arena.main();
return 0;
}
示例5: TEST
TEST(ArenaTest, AllocateStringPiece) {
Arena arena;
toft::StringPiece origin = "hello world";
toft::StringPiece copy = arena.Allocate(origin);
EXPECT_EQ(origin, copy);
EXPECT_NE(origin.data(), copy.data());
EXPECT_EQ(copy.data(), arena.current_block());
}
示例6: get_MethodData
void ciMethodData::load_data() {
MethodData* mdo = get_MethodData();
if (mdo == NULL) {
return;
}
// To do: don't copy the data if it is not "ripe" -- require a minimum #
// of invocations.
// Snapshot the data -- actually, take an approximate snapshot of
// the data. Any concurrently executing threads may be changing the
// data as we copy it.
Copy::disjoint_words((HeapWord*) mdo,
(HeapWord*) &_orig,
sizeof(_orig) / HeapWordSize);
Arena* arena = CURRENT_ENV->arena();
_data_size = mdo->data_size();
_extra_data_size = mdo->extra_data_size();
int total_size = _data_size + _extra_data_size;
_data = (intptr_t *) arena->Amalloc(total_size);
Copy::disjoint_words((HeapWord*) mdo->data_base(), (HeapWord*) _data, total_size / HeapWordSize);
// Traverse the profile data, translating any oops into their
// ci equivalents.
ResourceMark rm;
ciProfileData* ci_data = first_data();
ProfileData* data = mdo->first_data();
while (is_valid(ci_data)) {
ci_data->translate_from(data);
ci_data = next_data(ci_data);
data = mdo->next_data(data);
}
if (mdo->parameters_type_data() != NULL) {
_parameters = data_layout_at(mdo->parameters_type_data_di());
ciParametersTypeData* parameters = new ciParametersTypeData(_parameters);
parameters->translate_from(mdo->parameters_type_data());
}
load_extra_data();
// Note: Extra data are all BitData, and do not need translation.
_current_mileage = MethodData::mileage_of(mdo->method());
_invocation_counter = mdo->invocation_count();
_backedge_counter = mdo->backedge_count();
_state = mdo->is_mature()? mature_state: immature_state;
_eflags = mdo->eflags();
_arg_local = mdo->arg_local();
_arg_stack = mdo->arg_stack();
_arg_returned = mdo->arg_returned();
#ifndef PRODUCT
if (ReplayCompiles) {
ciReplay::initialize(this);
}
#endif
}
示例7: fetchNextFreeArena
Arena*
Chunk::allocateArena(JSRuntime* rt, Zone* zone, AllocKind thingKind, const AutoLockGC& lock)
{
Arena* arena = info.numArenasFreeCommitted > 0
? fetchNextFreeArena(rt)
: fetchNextDecommittedArena();
arena->init(zone, thingKind);
updateChunkListAfterAlloc(rt, lock);
return arena;
}
示例8: traverse
void traverse(const Arena& arena) // Build up the name
{
if (ArenaPtr p = arena.parent()) // Has a parent arena?
{
traverse(*p); // ...traverse parent
*this += '/'; // ...add a delimiter
}
*this += arena.name(); // Append arena name
}
示例9: m_level
Spawner::Spawner(Arena& arena): m_level(1),
m_spawnDelay(sf::seconds(1.0f)),
m_arenaSize(arena.getSize()),
m_doorSize
(
(arena.getSize().x / 2) - (arena.getSize().x / 6),
(arena.getSize().x / 2) + (arena.getSize().x / 6)
),
m_randLoc(0, 3)
{
}
示例10: assert
// ------------------------------------------------------------------
// ciMethod::load_code
//
// Load the bytecodes and exception handler table for this method.
void ciMethod::load_code() {
VM_ENTRY_MARK;
assert(is_loaded(), "only loaded methods have code");
methodOop me = get_methodOop();
Arena* arena = CURRENT_THREAD_ENV->arena();
// Load the bytecodes.
_code = (address)arena->Amalloc(code_size());
memcpy(_code, me->code_base(), code_size());
// Revert any breakpoint bytecodes in ci's copy
if (me->number_of_breakpoints() > 0) {
BreakpointInfo* bp = instanceKlass::cast(me->method_holder())->breakpoints();
for (; bp != NULL; bp = bp->next()) {
if (bp->match(me)) {
code_at_put(bp->bci(), bp->orig_bytecode());
}
}
}
// And load the exception table.
typeArrayOop exc_table = me->exception_table();
// Allocate one extra spot in our list of exceptions. This
// last entry will be used to represent the possibility that
// an exception escapes the method. See ciExceptionHandlerStream
// for details.
_exception_handlers =
(ciExceptionHandler**)arena->Amalloc(sizeof(ciExceptionHandler*)
* (_handler_count + 1));
if (_handler_count > 0) {
for (int i=0; i<_handler_count; i++) {
int base = i*4;
_exception_handlers[i] = new (arena) ciExceptionHandler(
holder(),
/* start */ exc_table->int_at(base),
/* limit */ exc_table->int_at(base+1),
/* goto pc */ exc_table->int_at(base+2),
/* cp index */ exc_table->int_at(base+3));
}
}
// Put an entry at the end of our list to represent the possibility
// of exceptional exit.
_exception_handlers[_handler_count] =
new (arena) ciExceptionHandler(holder(), 0, code_size(), -1, 0);
if (CIPrintMethodCodes) {
print_codes();
}
}
示例11: attack
/*********************************************************************************
*Description - Attack fn Fn that passes number of die and die faces to Arena fn
*Parameters - CONST for number of die and die faces
*********************************************************************************/
void Reptile::attack() {
int attack;
battle3.setNumFaces(R_ATTACK_FACE);
battle3.setNumDice(R_ATTACK_DIE);
attack = battle3.Roll();
cout << "The Reptile People delivered a heavy blow to the opponent with a force of: " << attack << endl;
battle3.setAttackRoll(attack);
}
示例12: initVec
void ESFinder::initVec(vec &psi, const Arena &arena) {
const std::size_t N = psi.size();
VecTools::initRand(0);
for (std::size_t i=0; i<N; i++) {
const double pot = std::abs(arena.evaluatePotentialAtGridPoint(i));
const double rnd = VecTools::getRandom(-pot, pot);
psi[i] = rnd;
}
const double dx = arena.getStepSizeX();
VecTools::normalize(psi, dx);
}
示例13: checkDescriptor
void Map::optimize(const fs::path& directory, const fs::path& target,
const Options& options) {
const auto descriptor = internal::Descriptor::readFromDirectory(directory);
checkDescriptor(descriptor, directory);
fs::path prefix = directory / getPartitionPrefix(0);
const Stats stats = internal::Partition::stats(prefix);
Options new_options = options;
new_options.error_if_exists = true;
new_options.create_if_missing = true;
if (options.block_size == 0) {
new_options.block_size = stats.block_size;
}
if (options.num_partitions == 0) {
new_options.num_partitions = descriptor.num_partitions;
}
Map new_map(target, new_options);
for (int i = 0; i < descriptor.num_partitions; i++) {
prefix = directory / getPartitionPrefix(i);
if (options.verbose) {
mt::log() << "Optimizing partition " << (i + 1) << " of "
<< descriptor.num_partitions << std::endl;
}
if (options.compare) {
Arena arena;
std::vector<Slice> values;
internal::Partition::forEachEntry(
prefix, [&new_map, &arena, &options, &values](const Slice& key,
Iterator* iter) {
arena.deallocateAll();
values.reserve(iter->available());
values.clear();
while (iter->hasNext()) {
values.push_back(iter->next().makeCopy(&arena));
}
std::sort(values.begin(), values.end(), options.compare);
for (const auto& value : values) {
new_map.put(key, value);
}
});
} else {
internal::Partition::forEachEntry(
prefix, [&new_map](const Slice& key, Iterator* iter) {
while (iter->hasNext()) {
new_map.put(key, iter->next());
}
});
}
}
}
示例14: attemptMove
// Return false without changing anything if moving one step from (r,c)
// in the indicated direction would hit a run off the edge of the arena.
// Otherwise, update r and c to the position resulting from the move and
// return true.
bool attemptMove(const Arena& a, int dir, int& r, int& c)
{
int rnew = r;
int cnew = c;
switch (dir)
{
case NORTH: if (r <= 1) return false; else rnew--; break;
case EAST: if (c >= a.cols()) return false; else cnew++; break;
case SOUTH: if (r >= a.rows()) return false; else rnew++; break;
case WEST: if (c <= 1) return false; else cnew--; break;
}
r = rnew;
c = cnew;
return true;
}
示例15: dropBrain
string Player::dropBrain()
{
if (m_arena->getCellStatus(m_row, m_col) == HAS_BRAIN)
return "There's already a brain at this spot.";
m_arena->setCellStatus(m_row, m_col, HAS_BRAIN);
return "A brain has been dropped.";
}