00001
00002
00003
00004
00005 #include "commandCache.h"
00006
00007 #include "command.h"
00008 #include "node.h"
00009 #include "packets.h"
00010
00011 using namespace std;
00012
00013 namespace eq
00014 {
00015 namespace net
00016 {
00017 CommandCache::CommandCache()
00018 {}
00019
00020 CommandCache::~CommandCache()
00021 {
00022 flush();
00023 }
00024
00025 void CommandCache::flush()
00026 {
00027 for( vector< Command* >::const_iterator i = _freeCommands.begin();
00028 i != _freeCommands.end(); ++i )
00029 {
00030 Command* command = *i;
00031 delete command;
00032 }
00033 _freeCommands.clear();
00034 }
00035
00036 Command* CommandCache::alloc( Command& inCommand )
00037 {
00038 Command* outCommand;
00039
00040 if( _freeCommands.empty( ))
00041 outCommand = new Command;
00042 else
00043 {
00044 outCommand = _freeCommands.back();
00045 _freeCommands.pop_back();
00046 }
00047
00048 outCommand->swap( inCommand );
00049 return outCommand;
00050 }
00051
00052 void CommandCache::release( Command* command )
00053 {
00054 #ifndef NDEBUG
00055
00056
00057
00058 command->allocate( 0, 0, 1 );
00059 #endif
00060
00061 if( command->isValid() && (*command)->exceedsMinSize( ))
00062
00063 command->release();
00064
00065 _freeCommands.push_back( command );
00066 }
00067 }
00068 }