class LogStoreMemory : public LogStore
{
static unsigned int const MEM_SIZE = 2000000;
public:
LogStoreMemory() : m_NumRecords(0), m_CurrentIndex(0) {}
void store(LogRecord* record)
{
unsigned int size = record->getSize();
memcpy(&m_Buff[m_CurrentIndex], &size, sizeof(size));
m_CurrentIndex += sizeof(size);
record->store( &m_Buff[m_CurrentIndex] );
m_CurrentIndex += size;
}
void outputAll(ostream& out)
{
LogRecord* record;
unsigned int size;
for( int index=0; index < m_CurrentIndex; )
{
memcpy( &size, &m_Buff[index], sizeof(size) );
index += sizeof(size);
record = new LogRecord( &m_Buff[index], size );
record->print(out);
delete record;
index += size;
}
}
....
private:
char m_Buff[MEM_SIZE];
unsigned int m_NumRecords;
unsigned int m_CurrentIndex;
....
};
End of Listing