quindi ho tutto il codice del buffer circolare così:
codice:
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <boost/circular_buffer.hpp>
using namespace std;
using namespace boost;
void getDateTime(char * szTime);
const int numbuff = 3;
const int buflen = 30;
struct cBuffer
{
char data[1024];
int bytesRecorded;
bool flag;
cBuffer(char * data_, int bytesRecorded_, bool flag_) :
bytesRecorded(bytesRecorded_), flag(flag_)
{
memcpy(static_cast<void *>(data), static_cast<void *>(data_), bytesRecorded);
}
};
int main()
{
circular_buffer<cBuffer> cb(numbuff);
// Insert elements
printf("Push elements:\n");
for(int i = 0; i < 5; i++)
{
char szTime[30]; getDateTime(szTime);
cb.push_back(cBuffer(szTime, 30, true));
printf("%s\n", szTime);
Sleep(1000);
}
// Show elements:
printf("Show elements:\n");
for(int i = 0; i<(int)cb.size(); i++)
{
printf("%s\n", cb[i].data);
}
system("pause");
return EXIT_SUCCESS;
}
void getDateTime(char * szTime)
{
time_t rawtime = time(NULL);
struct tm timeinfo;
gmtime_s(&timeinfo, &rawtime);
strftime(szTime, 30, "%a, %d %b %Y %X GMT", &timeinfo);
}
penso che ora davvero non incorrerò in memory leaks...
grazie