Panda3D
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends

SimpleLru Class Reference

An implementation of a very simple LRU algorithm. More...

#include "simpleLru.h"

Inheritance diagram for SimpleLru:
LinkedListNode Namable

List of all members.

Public Member Functions

 SimpleLru (const string &name, size_t max_size)
void begin_epoch ()
 Marks the end of the previous epoch and the beginning of the next one.
void clear_name ()
 Resets the Namable's name to empty.
void consider_evict ()
 Evicts a sequence of objects if the queue is full.
size_t count_active_size () const
 Returns the total size of the pages that were enqueued since the last call to begin_epoch().
void evict_to (size_t target_size)
 Evicts a sequence of objects until the queue fits within the indicated target size, regardless of its normal max size.
size_t get_max_size () const
 Returns the max size of all objects that are allowed to be active on the LRU.
const string & get_name () const
size_t get_total_size () const
 Returns the total size of all objects currently active on the LRU.
bool has_name () const
 Returns true if the Namable has a nonempty name set, false if the name is empty.
void output (ostream &out) const
 Outputs the Namable.
void set_max_size (size_t max_size)
 Changes the max size of all objects that are allowed to be active on the LRU.
void set_name (const string &name)
bool validate ()
 Checks that the LRU is internally self-consistent.
void write (ostream &out, int indent_level) const

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()

Static Public Attributes

static LightMutex_global_lock = *new LightMutex

Protected Member Functions

void insert_after (LinkedListNode *node)
 Adds a LinkedListNode record after the indicated node in the doubly-linked list.
void insert_before (LinkedListNode *node)
 Adds a LinkedListNode record before the indicated node in the doubly-linked list.
bool is_on_list () const
 Returns true if the node is member of any list, false if it has been removed or never added.
void remove_from_list ()
 Removes a LinkedListNode record from the doubly-linked list.
void take_list_from (LinkedListNode *other_root)
 Given that this LinkedListNode represents the root of a list, and the other pointer represents the root of a different list, move all of the nodes (except the root itself) from other_root onto this list.

Protected Attributes

LinkedListNode_next
LinkedListNode_prev

Friends

class SimpleLruPage

Detailed Description

An implementation of a very simple LRU algorithm.

Also see AdaptiveLru.

Definition at line 31 of file simpleLru.h.


Member Function Documentation

void SimpleLru::begin_epoch ( ) [inline]

Marks the end of the previous epoch and the beginning of the next one.

This will evict any objects that are pending eviction, and also update any internal bookkeeping.

Definition at line 94 of file simpleLru.I.

References consider_evict(), and SimpleLruPage::enqueue_lru().

Referenced by GeomVertexArrayData::lru_epoch().

void Namable::clear_name ( ) [inline, inherited]

Resets the Namable's name to empty.

Reimplemented in AsyncTask.

Definition at line 64 of file namable.I.

void SimpleLru::consider_evict ( ) [inline]

Evicts a sequence of objects if the queue is full.

Definition at line 63 of file simpleLru.I.

Referenced by begin_epoch().

size_t SimpleLru::count_active_size ( ) const

Returns the total size of the pages that were enqueued since the last call to begin_epoch().

Definition at line 106 of file simpleLru.cxx.

void SimpleLru::evict_to ( size_t  target_size) [inline]

Evicts a sequence of objects until the queue fits within the indicated target size, regardless of its normal max size.

Definition at line 78 of file simpleLru.I.

size_t SimpleLru::get_max_size ( ) const [inline]

Returns the max size of all objects that are allowed to be active on the LRU.

Definition at line 35 of file simpleLru.I.

Referenced by VertexDataPage::evict_lru().

size_t SimpleLru::get_total_size ( ) const [inline]

Returns the total size of all objects currently active on the LRU.

Definition at line 23 of file simpleLru.I.

Referenced by GraphicsEngine::render_frame().

bool Namable::has_name ( ) const [inline, inherited]
void LinkedListNode::insert_after ( LinkedListNode node) [inline, protected, inherited]

Adds a LinkedListNode record after the indicated node in the doubly-linked list.

Definition at line 108 of file linkedListNode.I.

void LinkedListNode::insert_before ( LinkedListNode node) [inline, protected, inherited]

Adds a LinkedListNode record before the indicated node in the doubly-linked list.

Definition at line 91 of file linkedListNode.I.

Referenced by SimpleAllocator::do_alloc(), AdaptiveLru::do_partial_lru_update(), and SimpleLruPage::enqueue_lru().

bool LinkedListNode::is_on_list ( ) const [inline, protected, inherited]

Returns true if the node is member of any list, false if it has been removed or never added.

The head of a list generally appears to to always be a member of itself.

Definition at line 62 of file linkedListNode.I.

void SimpleLru::output ( ostream &  out) const

Outputs the Namable.

This function simply writes the name to the output stream; most Namable derivatives will probably redefine this.

Reimplemented from Namable.

Definition at line 125 of file simpleLru.cxx.

void LinkedListNode::remove_from_list ( ) [inline, protected, inherited]

Removes a LinkedListNode record from the doubly-linked list.

Definition at line 73 of file linkedListNode.I.

Referenced by SimpleLruPage::dequeue_lru(), SimpleAllocatorBlock::do_free(), AdaptiveLru::do_partial_lru_update(), and SimpleLruPage::enqueue_lru().

void SimpleLru::set_max_size ( size_t  max_size) [inline]

Changes the max size of all objects that are allowed to be active on the LRU.

If the size is (size_t)-1, there is no limit.

Definition at line 49 of file simpleLru.I.

void LinkedListNode::take_list_from ( LinkedListNode other_root) [inline, protected, inherited]

Given that this LinkedListNode represents the root of a list, and the other pointer represents the root of a different list, move all of the nodes (except the root itself) from other_root onto this list.

Definition at line 127 of file linkedListNode.I.

Referenced by BufferContextChain::take_from().

bool SimpleLru::validate ( ) [inline]

Checks that the LRU is internally self-consistent.

Returns true if successful, false if there is some problem.

Definition at line 107 of file simpleLru.I.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations