|
-
January 25th, 2010, 03:32 PM
#11
Re: memory leaks
Looks like you aren't taking advantage of c++ at all. this looks like c with classes approach with boost?
Code:
#include <windows.h>
#include <ctime>
#include <string>
#include <iostream>
#include <boost/circular_buffer.hpp>
#include <boost/foreach.hpp>
using namespace std;
using namespace boost;
string getDateTime()
{
time_t rawtime = time(NULL);
tm* timeinfo = gmtime(&rawtime);
char szTime[30];
strftime(szTime, 30, "%a, %d %b %Y %X GMT", timeinfo);
return szTime;
}
struct Buffer
{
string payload;
int user;
Buffer() : payload(), user() { }
Buffer( const string& payload, int user ) : payload(payload), user(user) { }
};
int main()
{
const int numbuff = 3;
circular_buffer<Buffer> cb(numbuff);
// Insert elements
cout << "Push elements:" << endl;
for( int i = 0; i < 5; i++ )
{
cb.push_back( Buffer( getDateTime(), i ) );
Sleep(1000);
}
// Show elements:
cout << "Show elements:" << endl;
BOOST_FOREACH( Buffer Record, cb )
cout << Record.payload << endl;
system("pause");
return 0;
}
This is more c++ than the c approach , but understanding how and why to use string, constructors, containers and etc will take time. If this isn't what you require, just state what is wrong with the above code.
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|