Re: memory leaks
"Bo Persson" <bop@gmb.dk> ha scritto nel messaggio
news:7s60mgFd8jU1@mid.individual.net...
So, if it is not a string you could try std::vector<unsigned char>
instead. That's a good type for a byte buffer.
That's what I have been looking for!
Anyway now I have trouble with the following:
void getDateTime(char * szTime);
const int numbuff = 5;
const int buflen = 30;
struct Buffer
{
public:
vector<char> vChar;
unsigned int bufferLength;
unsigned int bytesRecorded;
Buffer() : bytesRecorded(0), bufferLength(0), vChar(NULL) { };
};
int main()
{
circular_buffer<Buffer> cb(numbuff);
circular_buffer<Buffer>::const_iterator it;
for(int i = 0; i<10; i++)
{
// Get time
char szTime[30]; getDateTime(szTime);
// Init Buff
Buffer buff;
ZeroMemory(&buff, sizeof(Buffer));
buff.vChar.resize(buflen);
buff.vChar = szTime;
buff.bufferLength = buflen;
buff.bytesRecorded = buflen;
printf("%s\n", buff.vChar);
}
system("pause");
return EXIT_SUCCESS;
}
// getDateTime (Fri, 10 Oct 2008 14:41:59 GMT)
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);
}
The code fails here: buff.vChar = szTime;
???
thanks