本文整理汇总了C++中FreeList类的典型用法代码示例。如果您正苦于以下问题:C++ FreeList类的具体用法?C++ FreeList怎么用?C++ FreeList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FreeList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LazyBuffer
// The Constructor
inline LazyBuffer( const string& offsetFile, const string& dataFile, int direction=LAZY_BUFFER_INPUT ) : limit(-1)
{
type = direction;
datafile = dataFile;
offsetfile = offsetFile;
if ( LAZY_BUFFER_INPUT == direction ) {
WITH_OPEN( in, offsetFile.c_str(), "rb" );
int len = 0;
fread( &len, sizeof(int), 1, in );
forward_ptr.resize( len );
offsets.resize( len );
backward_ptr.clear();
items.clear();
hash.clear();
for ( auto& item : forward_ptr ) item = -1; // the forward_ptr is zero
for ( auto& item : offsets ) fread( &item, sizeof(long), 1, in );
fdata = fopen( dataFile.c_str(), "rb" );
// Initialize the FreeList
fl.init( len );
END_WITH( in );
} else if ( LAZY_BUFFER_CREATE == direction ) {
fl.init(0);
forward_ptr.clear();
backward_ptr.clear();
offsets.clear();
items.clear();
hash.clear();
fdata = nullptr;
} else {
Error( "LazyBuffer(): Wrong Parameter for direction in constructor." );
}
}
示例2: threadFunc
void threadFunc(FreeList& pool, ros::atomic<bool>& done, ros::atomic<bool>& failed, boost::barrier& b)
{
b.wait();
//ROS_INFO_STREAM("Thread " << boost::this_thread::get_id() << " starting");
uint32_t* vals[10];
uint64_t alloc_count = 0;
while (!done.load())
{
for (uint32_t i = 0; i < 10; ++i)
{
vals[i] = static_cast<uint32_t*>(pool.allocate());
if (vals[i])
{
++alloc_count;
*vals[i] = i;
}
else
{
ROS_ERROR_STREAM("Thread " << boost::this_thread::get_id() << " failed to allocate");
}
}
for (uint32_t i = 0; i < 10; ++i)
{
if (vals[i])
{
if (*vals[i] != i)
{
ROS_ERROR_STREAM("Thread " << boost::this_thread::get_id() << " val " << vals[i] << " " << i << " = " << *vals[i]);
failed.store(true);
}
pool.free(vals[i]);
}
}
if (failed.load())
{
#if FREE_LIST_DEBUG
boost::mutex::scoped_lock lock(g_debug_mutex);
g_debug.push_back(*pool.getDebug());
#endif
return;
}
}
//ROS_INFO_STREAM("Thread " << boost::this_thread::get_id() << " allocated " << alloc_count << " blocks");
}
示例3: malloc
void*
malloc ()
{
if (freeList.empty ())
{
allocateChunk ();
}
FreeListNode *node = &freeList.front ();
freeList.pop_front ();
node->~slist_base_hook<> ();
++mallocCount;
return reinterpret_cast<void*> (node);
}
示例4: free
void
free (void* t)
{
FreeListNode *node = reinterpret_cast<FreeListNode*> (t);
new (node) FreeListNode;
freeList.push_front (*node);
++freeCount;
assert(([this]()->bool
{ // check we have no double-frees
std::set<FreeListNode*> s;
for(auto &n: freeList) s.insert(&n);
return s.size() == freeList.size();
}) ());
}
示例5: allocateChunk
void
allocateChunk ()
{
chunks.push_back (new Chunk); // requires c++17 new with alignment
for (Storage& storage : chunks.back ())
{
FreeListNode *node = reinterpret_cast<FreeListNode*> (&storage);
new (node) FreeListNode;
freeList.push_front (*node);
}
}
示例6: ASSERT
void* MarkedAllocator::tryAllocateIn(MarkedBlock::Handle* block)
{
ASSERT(block);
ASSERT(!block->hasAnyNewlyAllocated());
ASSERT(!block->isFreeListed());
FreeList freeList = block->sweep(MarkedBlock::Handle::SweepToFreeList);
// It's possible to stumble on a completely full block. Marking tries to retire these, but
// that algorithm is racy and may forget to do it sometimes.
if (freeList.allocationWillFail()) {
ASSERT(block->isFreeListed());
block->unsweepWithNoNewlyAllocated();
ASSERT(!block->isFreeListed());
ASSERT(!isEmpty(block));
ASSERT(!isCanAllocateButNotEmpty(block));
return nullptr;
}
m_currentBlock = block;
setFreeList(freeList);
void* result;
if (m_freeList.remaining) {
unsigned cellSize = m_cellSize;
m_freeList.remaining -= cellSize;
result = m_freeList.payloadEnd - m_freeList.remaining - cellSize;
} else {
FreeCell* head = m_freeList.head;
m_freeList.head = head->next;
result = head;
}
RELEASE_ASSERT(result);
setIsEden(m_currentBlock, true);
m_markedSpace->didAllocateInBlock(m_currentBlock);
return result;
}
示例7: operator
// Const access and load on demand
inline const ItemType& operator()( const int i )
{
assert( i < static_cast<int>( forward_ptr.size() ) );
if ( -1 == forward_ptr[i] ) {
assert( LAZY_BUFFER_INPUT == type );
if ( -1 != limit && static_cast<int>( backward_ptr.size() ) >= limit ) {
int pos = fl.discard();
int unload = forward_ptr[pos];
forward_ptr[pos] = -1;
assert( -1 != unload );
fseek( fdata, offsets[i], SEEK_SET );
items[unload] = std::move( ItemType( fdata ) );
forward_ptr[i] = unload;
backward_ptr[unload] = i;
} else {
fseek( fdata, offsets[i], SEEK_SET );
items.push_back( std::move( ItemType( fdata ) ) );
forward_ptr[i] = static_cast<int>( items.size() - 1 );
backward_ptr.push_back( i );
assert( backward_ptr.size() == items.size() );
}
fl.promote( i );
} else {
assert( ( 0 <= forward_ptr[i] ) && ( forward_ptr[i] < static_cast<int>( items.size() ) ) );
}
return items[forward_ptr[i]];
}
示例8: StartScene
void GLDrawInfo::StartScene()
{
sectorrenderflags.Resize(numsectors);
ss_renderflags.Resize(numsubsectors);
memset(§orrenderflags[0], 0, numsectors*sizeof(sectorrenderflags[0]));
memset(&ss_renderflags[0], 0, numsubsectors*sizeof(ss_renderflags[0]));
for(unsigned int i=0;i< otherfloorplanes.Size();i++)
{
gl_subsectorrendernode * node = otherfloorplanes[i];
while (node)
{
gl_subsectorrendernode * n = node;
node = node->next;
SSR_List.Release(n);
}
}
otherfloorplanes.Clear();
for(unsigned int i=0;i< otherceilingplanes.Size();i++)
{
gl_subsectorrendernode * node = otherceilingplanes[i];
while (node)
{
gl_subsectorrendernode * n = node;
node = node->next;
SSR_List.Release(n);
}
}
otherceilingplanes.Clear();
// clear all the lists that might not have been cleared already
MissingUpperTextures.Clear();
MissingLowerTextures.Clear();
MissingUpperSegs.Clear();
MissingLowerSegs.Clear();
SubsectorHacks.Clear();
CeilingStacks.Clear();
FloorStacks.Clear();
HandledSubsectors.Clear();
next=gl_drawinfo;
gl_drawinfo=this;
for(int i=0;i<GLDL_TYPES;i++) drawlists[i].Reset();
}
示例9: EndDrawInfo
//==========================================================================
//
//
//
//==========================================================================
void GLDrawInfo::EndDrawInfo()
{
GLDrawInfo * di = gl_drawinfo;
for(int i=0;i<GLDL_TYPES;i++) di->drawlists[i].Reset();
gl_drawinfo=di->next;
if (di->temporary) di_list.Release(di);
}
示例10: StartDrawInfo
//==========================================================================
//
// Sets up a new drawinfo struct
//
//==========================================================================
void GLDrawInfo::StartDrawInfo(GLDrawInfo * di)
{
if (!di)
{
di=di_list.GetNew();
di->temporary=true;
}
di->StartScene();
}
示例11: evacuate
inline void evacuate()
{
assert( LAZY_BUFFER_INPUT == type );
for ( auto& ele : backward_ptr ) {
forward_ptr[ele] = -1;
fl.discard();
}
backward_ptr.clear();
items.clear();
}
示例12: ClearBuffers
void FDrawInfo::ClearBuffers()
{
for(unsigned int i=0; i< otherfloorplanes.Size(); i++)
{
gl_subsectorrendernode * node = otherfloorplanes[i];
while (node)
{
gl_subsectorrendernode * n = node;
node = node->next;
SSR_List.Release(n);
}
}
otherfloorplanes.Clear();
for(unsigned int i=0; i< otherceilingplanes.Size(); i++)
{
gl_subsectorrendernode * node = otherceilingplanes[i];
while (node)
{
gl_subsectorrendernode * n = node;
node = node->next;
SSR_List.Release(n);
}
}
otherceilingplanes.Clear();
// clear all the lists that might not have been cleared already
MissingUpperTextures.Clear();
MissingLowerTextures.Clear();
MissingUpperSegs.Clear();
MissingLowerSegs.Clear();
SubsectorHacks.Clear();
CeilingStacks.Clear();
FloorStacks.Clear();
HandledSubsectors.Clear();
}
示例13: DeleteLightNode
static FLightNode * DeleteLightNode(FLightNode * node)
{
FLightNode * tn; // next node on thing thread
if (node)
{
*node->prevTarget = node->nextTarget;
if (node->nextTarget) node->nextTarget->prevTarget=node->prevTarget;
*node->prevLight = node->nextLight;
if (node->nextLight) node->nextLight->prevLight=node->prevLight;
// Return this node to the freelist
tn=node->nextTarget;
freelist.Release(node);
return(tn);
}
return(NULL);
} // phares 3/13/98
示例14: AddLightNode
FLightNode * AddLightNode(FLightNode ** thread, void * linkto, ADynamicLight * light, FLightNode *& nextnode)
{
FLightNode * node;
node = nextnode;
while (node)
{
if (node->targ==linkto) // Already have a node for this sector?
{
node->lightsource = light; // Yes. Setting m_thing says 'keep it'.
return(nextnode);
}
node = node->nextTarget;
}
// Couldn't find an existing node for this sector. Add one at the head
// of the list.
node = freelist.GetNew();
node->targ = linkto;
node->lightsource = light;
node->prevTarget = &nextnode;
node->nextTarget = nextnode;
if (nextnode) nextnode->prevTarget = &node->nextTarget;
// Add new node at head of sector thread starting at s->touching_thinglist
node->prevLight = thread;
node->nextLight = *thread;
if (node->nextLight) node->nextLight->prevLight=&node->nextLight;
*thread = node;
return(node);
}
示例15: HandleHackedSubsectors
void FDrawInfo::HandleHackedSubsectors()
{
lowershcount=uppershcount=0;
totalssms.Reset();
totalssms.Clock();
viewsubsector = R_PointInSubsector(viewx, viewy);
// Each subsector may only be processed once in this loop!
validcount++;
for(unsigned int i=0; i<SubsectorHacks.Size(); i++)
{
subsector_t * sub = SubsectorHacks[i].sub;
if (sub->validcount!=validcount && CheckAnchorFloor(sub))
{
// Now collect everything that is connected with this subsector.
HandledSubsectors.Clear();
inview=false;
lowersegs.Clear();
if (CollectSubsectorsFloor(sub, sub->render_sector))
{
for(unsigned int j=0; j<HandledSubsectors.Size(); j++)
{
gl_subsectorrendernode * node = SSR_List.GetNew();
node->sub = HandledSubsectors[j];
AddOtherFloorPlane(sub->render_sector->sectornum, node);
}
if (inview) for(unsigned int j=0; j<lowersegs.Size(); j++)
{
seg_t * seg=lowersegs[j];
GLRenderer->ProcessLowerMiniseg (seg, seg->Subsector->render_sector, seg->PartnerSeg->Subsector->render_sector);
}
lowershcount+=HandledSubsectors.Size();
}
}
}
// Each subsector may only be processed once in this loop!
validcount++;
for(unsigned int i=0; i<SubsectorHacks.Size(); i++)
{
subsector_t * sub = SubsectorHacks[i].sub;
if (sub->validcount!=validcount && CheckAnchorCeiling(sub))
{
// Now collect everything that is connected with this subsector.
HandledSubsectors.Clear();
if (CollectSubsectorsCeiling(sub, sub->render_sector))
{
for(unsigned int j=0; j<HandledSubsectors.Size(); j++)
{
gl_subsectorrendernode * node = SSR_List.GetNew();
node->sub = HandledSubsectors[j];
AddOtherCeilingPlane(sub->render_sector->sectornum, node);
}
uppershcount+=HandledSubsectors.Size();
}
}
}
SubsectorHacks.Clear();
totalssms.Unclock();
}