Monday, January 25, 2010

comp.lang.c++ - 25 new messages in 6 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* memory leaks - 13 messages, 6 authors
http://groups.google.com/group/comp.lang.c++/t/d9b20823062f2cb3?hl=en
* ۞_۞free shipping wholesale low price nike shox shoes and ed hardy Jeans etc (
www.ecyaya.com) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/4a1a06e6e0fe3313?hl=en
* Support for export keyword ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0878ed0c9c1ca584?hl=en
* std::vector<boost::xpressive::sregex> fails to compile using gcc - 1
messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/3bb89df1dac2c2c6?hl=en
* Object (de)serialization - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/9fc67e8f28fe4918?hl=en
* Memory contents mysteriously changing - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/d3d7f50cba06cf27?hl=en

==============================================================================
TOPIC: memory leaks
http://groups.google.com/group/comp.lang.c++/t/d9b20823062f2cb3?hl=en
==============================================================================

== 1 of 13 ==
Date: Mon, Jan 25 2010 8:14 am
From: "Alf P. Steinbach"


* Larry:
> Hi,
>
> do you think the following code could lead to memory leaks? it creates
> a circualr buffer made up of 5 element then it pushes 10 elements
> (overwriting the first 5) when overwriting , do you think the eldest
> pointed memory will be overwritten, or a new pointer in memory will be
> written?

The question is unclear, but yes, you have memory leaks.

The memory leaks are due to coding at the C level.

In C++ use library classes, such as replacing your Buffer with std::string. :-)

> #define _CRT_SECURE_NO_WARNINGS

Don't do that.


> #include <windows.h>
> #include <vector>
> #include <cstdlib>
> #include <ctime>
> #include <cstdio>
> #include <boost/circular_buffer.hpp>
> using namespace std;
> using namespace boost;
>
> char * getDateTime(void);

Let that function return std::string.

By the way, 'void' as argument type is a C-ism.

It doesn't make much sense in C++.


> const short numbuff = 5;
> const short buflen = 30;

This confuses two different kinds of buffers: your circular buffer with room for
5 strings, and your string type named "Buffer" with room for 30 characters.

You don't need the latter constant.

For the first constant, consider replacing 'short' with 'int': there's no good
reason to choose anything but 'int' here.


> typedef struct
> {
> unsigned char * pData;
> unsigned short bufferLength;
> unsigned short bytesRecorded;
> bool flag;
> } Buffer;

Just remove that.


> int main()
> {
> circular_buffer<Buffer*> cb(numbuff);

This would be

circular_buffer<string> timeStrings( bufferSize );


> circular_buffer<Buffer*>::const_iterator it;
>
> printf("Push elements:\n");
> // fill buffer
> for(int i = 0; i<10; i++)
> {
> // set up buffer
> Buffer *buff = new Buffer;
> ZeroMemory(buff, sizeof(Buffer));
>
> buff->bufferLength = buflen;
> buff->bytesRecorded = buflen;
> buff->flag = true;
> buff->pData = new unsigned char[buflen];
> buff->pData = reinterpret_cast<unsigned char *>(getDateTime());

Don't cast.

>
> printf("%s\n", buff->pData);
>
> // push buffer
> cb.push_back(buff);

This would be simply

timeStrings.push_back( getDateTime() );


> Sleep(1000);
> }
>
> printf("\nShow elements:\n");
>
> // show elements
> for(int i = 0; i<static_cast<int>(cb.size()); i++)
> {
> printf("%s\n", cb[i]->pData);
> }
>
> system("pause");
> return EXIT_SUCCESS;
> }
>
> // getDateTime (Fri, 10 Oct 2008 14:41:59 GMT)
> char * getDateTime(void)
> {
> time_t rawtime;
> struct tm * timeinfo;
> time(&rawtime);
> timeinfo = gmtime(&rawtime);
> char * buffer = new char[30];
> strftime(buffer,30,"%a, %d %b %Y %X GMT",timeinfo);
> return buffer;
> }

See above.


Cheers & hth.,

- Alf


== 2 of 13 ==
Date: Mon, Jan 25 2010 8:30 am
From: SG


On 25 Jan., 17:01, "Larry" <dontmewit...@got.it> wrote:
> Hi,
>    do you think the following code could lead to memory leaks?

Yes. In this case it's fairly easy to determine: You used the "new"-
operator three times but never the "delete"-operator and never passed
on the responsibility for managing the object life times to other
functions or objects.

> typedef struct
> {
>  unsigned char * pData;
>  unsigned short bufferLength;
>  unsigned short bytesRecorded;
>  bool flag;
> } Buffer;

Note: The type "Buffer" isn't responsible for managing the allocated
buffer. Otherwise you would have made the members private and added
allocation/deallocation/copy ctor/assignment operators.

> int main()
> {
>  circular_buffer<Buffer*> cb(numbuff);
>  circular_buffer<Buffer*>::const_iterator it;
>
>  printf("Push elements:\n");
>  // fill buffer
>  for(int i = 0; i<10; i++)
>  {
>   // set up buffer
>   Buffer *buff       = new Buffer;

These Buffer objects are never deleted.

>   ZeroMemory(buff, sizeof(Buffer));
>
>   buff->bufferLength  = buflen;
>   buff->bytesRecorded = buflen;
>   buff->flag          = true;
>   buff->pData         = new unsigned char[buflen];

These chunks of memory buff->pData points to are never deleted.

> // push buffer
> cb.push_back(buff);

The comment is wrong. You don't push a buffer. You push a pointer to a
struct that contains a pointer to the "buffer". That's the problem.
That's your leak. The container simply stores these pointers and is
not responsible for deleting your stuff. Containers generally don't
care about what kind of objects they store and they don't treat
pointers specially. Note: "object" and "pointer" are not mutually
exclusive. You can have an object that IS a pointer and containers a
la vector<int*> stores pointer objects. If you destroy a pointer,
nothing special happens -- specifically, the pointed to object is not
touched or free'd automatically.

> // getDateTime (Fri, 10 Oct 2008 14:41:59 GMT)
> char * getDateTime(void)
> {
> time_t rawtime;
> struct tm * timeinfo;
> time(&rawtime);
> timeinfo = gmtime(&rawtime);
> char * buffer = new char[30];
> strftime(buffer,30,"%a, %d %b %Y %X GMT",timeinfo);
> return buffer;
> }

Yet another new[] for which I don't see a delete[].

The rule is simple: If you new'd something you should delete it again
-- expect when you pass the pointer to some function or object that
_specifically_ takes ownership (responsibility for managing the life-
time) of the POINTEE (the thing the pointer points to).

Cheers,
SG


== 3 of 13 ==
Date: Mon, Jan 25 2010 8:33 am
From: "Larry"


"Alf P. Steinbach" <alfps@start.no> ha scritto nel messaggio
news:hjkg1c$88b$1@news.eternal-september.org...

> The question is unclear, but yes, you have memory leaks.
>
> The memory leaks are due to coding at the C level.
>
> In C++ use library classes, such as replacing your Buffer with
> std::string. :-)

That's great of you! Yet, I might be dealing with some data returned to me
as <unsigned char>. If it is possible to cast from unsigned char to string I
will be totally follow your advice. (I am dwaling with binary data mostly!)

thanks

== 4 of 13 ==
Date: Mon, Jan 25 2010 8:53 am
From: "Alf P. Steinbach"


* Larry:
> "Alf P. Steinbach" <alfps@start.no> ha scritto nel messaggio
> news:hjkg1c$88b$1@news.eternal-september.org...
>
>> The question is unclear, but yes, you have memory leaks.
>>
>> The memory leaks are due to coding at the C level.
>>
>> In C++ use library classes, such as replacing your Buffer with
>> std::string. :-)
>
> That's great of you! Yet, I might be dealing with some data returned to
> me as <unsigned char>. If it is possible to cast from unsigned char to
> string I will be totally follow your advice. (I am dwaling with binary
> data mostly!)

In practice you'll have to cast the pointer then, because
std::basic_string<unsigned char> is somewhere in the gray zone of not quite well
specified.

But other than that, the std::string constructors let you copy the data as
zero-terminated or as n bytes, whatever you have.

And std::string deals well with zero bytes, no problems.

However, if this is just raw data, consider

typedef unsigned char Byte;
typedef vector<Byte> ByteVector;

Cheers & hth.,

- Alf


== 5 of 13 ==
Date: Mon, Jan 25 2010 8:54 am
From: "Bo Persson"


Larry wrote:
> "Alf P. Steinbach" <alfps@start.no> ha scritto nel messaggio
> news:hjkg1c$88b$1@news.eternal-september.org...
>
>> The question is unclear, but yes, you have memory leaks.
>>
>> The memory leaks are due to coding at the C level.
>>
>> In C++ use library classes, such as replacing your Buffer with
>> std::string. :-)
>
> That's great of you! Yet, I might be dealing with some data
> returned to me as <unsigned char>. If it is possible to cast from
> unsigned char to string I will be totally follow your advice. (I am
> dwaling with binary data mostly!)
> thanks

So, if it is not a string you could try std::vector<unsigned char>
instead. That's a good type for a byte buffer.


Bo Persson


== 6 of 13 ==
Date: Mon, Jan 25 2010 9:04 am
From: "Larry"

"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

== 7 of 13 ==
Date: Mon, Jan 25 2010 9:25 am
From: "Larry"


"Alf P. Steinbach" <alfps@start.no> ha scritto nel messaggio
news:hjki9g$rc0$1@news.eternal-september.org...
>* Larry:
>> "Alf P. Steinbach" <alfps@start.no> ha scritto nel messaggio

> However, if this is just raw data, consider
>
> typedef unsigned char Byte;
> typedef vector<Byte> ByteVector;

the new struct should look like this:

struct Buffer
{
public:
vector<unsigned char> vuChar;
int bufferLength;
int bytesRecorded;
int user;
Buffer() : bytesRecorded(0), bufferLength(0), vChar(NULL), user(0) { };
};

what the difference between:
--> vector<unsigned char> vuChar;
and
--> unsigne char buffer[]

??

thanks

== 8 of 13 ==
Date: Mon, Jan 25 2010 9:35 am
From: Richard Herring


In message <4b5dcf0e$0$819$4fafbaef@reader5.news.tin.it>, Larry
<dontmewithme@got.it> writes
>
>"Bo Persson" <bop@gmb.dk> ha scritto nel messaggio
>news:7s60mgFd8jU1@mid.individual.net...

[aside: why is everyone posting low-level C code this week?]

>
>> 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!

You're using strftime and printf("%s") on it. That looks like a string
to me.
>
>Anyway now I have trouble with the following:
>
>void getDateTime(char * szTime);

Can't you make this into a function that returns a std::string?

>const int numbuff = 5;
>const int buflen = 30;
>
>struct Buffer
>{
>public:
>vector<char> vChar;
>unsigned int bufferLength;
>unsigned int bytesRecorded;

What's the point of bufferLength and bytesRecorded now? vector does its
own housekeeping, so there's no need for you to.

>Buffer() : bytesRecorded(0), bufferLength(0), vChar(NULL) { };

Lose that. vector's default constructor will work fine.

>};
>
>int main()
>{
>circular_buffer<Buffer> cb(numbuff);
>circular_buffer<Buffer>::const_iterator it;

You declare these but never use them.

>
>for(int i = 0; i<10; i++)
>{

And you do this 10 times for no good reason. I think you've lost track
of the need for a circular buffer somewhere along the way ;-(

> // Get time
> char szTime[30];

Is that 30 the same as the "buflen" you declared earlier?
Why the Hungarian prefix?

>getDateTime(szTime);
>
> // Init Buff
> Buffer buff;
> ZeroMemory(&buff, sizeof(Buffer));

Don't do that. Buffer's constructor should do all you need to do to
initialise it.
>
> buff.vChar.resize(buflen);

Don't do that. Assigning to the buffer will do all that's necessary.

> buff.vChar = szTime;

buff.vChar.assign(szTime, szTime+strlen(szTime));

Better still, give Buffer a constructor with appropriate arguments which
initialises the buffer.

> buff.bufferLength = buflen;
> buff.bytesRecorded = buflen;

Redundant. Just use buff.vChar.size();

>
> printf("%s\n", buff.vChar);

printf("%s\n", &buff.vChar[0]);

>}
>
>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);

Is that "30" the same as the "buflen" you declared earlier?

>}
>
>The code fails here: buff.vChar = szTime;

If you'd used string instead of vector<char> it would have worked ;-)
Because it's such a common operation, string (unlike vector) has an
assignment operator that takes a pointer to a C-style null-terminated
string.
>
>???

Try "Accelerated C++".

>
>thanks
>

--
Richard Herring


== 9 of 13 ==
Date: Mon, Jan 25 2010 10:42 am
From: "Larry"


"Richard Herring" <junk@[127.0.0.1]> ha scritto nel messaggio
news:Vvdt2izrZdXLFweM@baesystems.com...

> And you do this 10 times for no good reason. I think you've lost track of
> the need for a circular buffer somewhere along the way ;-(

I am just tring the circular buffer overwritten.

anyway the following code does not work:

#include <windows.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <boost/circular_buffer.hpp>
using namespace std;
using namespace boost;

void getDateTime(char * szTime);
const int numbuff = 5;
const int buflen = 30;

struct Buffer
{
public:
vector<char> vChar;
int bufferLength;
int bytesRecorded;
int user;
Buffer() : bytesRecorded(0), bufferLength(0), user(0) { };
};

int main()
{
circular_buffer<Buffer> cb(numbuff);
circular_buffer<Buffer>::const_iterator it;

// Insert elements
for(int i = 0; i<10; i++)
{
// Get time
char szTime[30]; getDateTime(szTime);

// Init Buff
Buffer buff;
copy(&szTime[0],&szTime[30],std::back_inserter(buff.vChar));

//buff.vChar.assign(szTime, szTime+strlen(szTime));
buff.bufferLength = buflen;
buff.bytesRecorded = buflen;
buff.user = i;

printf("%d, %d, %s\n", buff.user, buff.bufferLength, szTime);

cb.push_back(buff);
}

// Show elements:
for(int i = 0; i<(int)cb.size(); i++)
{
printf("%d, %d, %s\n", cb[i].user, cb[i].bufferLength, cb[i].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);
}

in the second loop I get <null> when I try to print vChar

NB: in the near future I may be deal with unsigned char data so that's why I
cannot have getDateTime() return std::string

== 10 of 13 ==
Date: Mon, Jan 25 2010 11:15 am
From: "Larry"


"SG" <s.gesemann@gmail.com> ha scritto nel messaggio
news:cd64ad64-151b-44a3-a974-9de7e7b18592@p24g2000yqm.googlegroups.com...

> Yes. In this case it's fairly easy to determine: You used the "new"-
> operator three times but never the "delete"-operator and never passed
> on the responsibility for managing the object life times to other
> functions or objects.

Ok! do you think the following may still lead to memory leaks?

#include <windows.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <boost/circular_buffer.hpp>
using namespace std;
using namespace boost;

void getDateTime(char * szTime);
const int numbuff = 5;
const int buflen = 30;

struct Buffer
{
public:
char * payload;
int bufferLength;
int bytesRecorded;
int user;
Buffer() : bytesRecorded(0), bufferLength(0), user(0), payload(NULL) { };
};

int main()
{
circular_buffer<Buffer> cb(numbuff);

// Insert elements
for(int i = 0; i<10; i++)
{
// Get time
char szTime[30]; getDateTime(szTime);

// Init Buff
Buffer buff;
buff.user = i;
buff.payload = szTime;
buff.bufferLength = buflen;
buff.bytesRecorded = buflen;

cb.push_back(buff);
}

// Show elements:
for(int i = 0; i<(int)cb.size(); i++)
{
printf("%d, %d, %s\n", cb[i].user, cb[i].bufferLength, cb[i].payload);
}

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);
}

thanks

== 11 of 13 ==
Date: Mon, Jan 25 2010 11:37 am
From: "Thomas J. Gritzan"


Am 25.01.2010 19:42, schrieb Larry:
> struct Buffer
> {
> public:
> vector<char> vChar;
> int bufferLength;
> int bytesRecorded;
> int user;
> Buffer() : bytesRecorded(0), bufferLength(0), user(0) { };
> };
>
> int main()
> {
> circular_buffer<Buffer> cb(numbuff);
> circular_buffer<Buffer>::const_iterator it;
>
> // Insert elements
> for(int i = 0; i<10; i++)
> {
> // Get time
> char szTime[30]; getDateTime(szTime);

Use your constants:
char szTime[buflen];

> // Init Buff
> Buffer buff;
> copy(&szTime[0],&szTime[30],std::back_inserter(buff.vChar));

This also works:
buff.vChar.assign(szTime, szTime+buflen);

> //buff.vChar.assign(szTime, szTime+strlen(szTime));
> buff.bufferLength = buflen;
> buff.bytesRecorded = buflen;
> buff.user = i;
>
> printf("%d, %d, %s\n", buff.user, buff.bufferLength, szTime);
>
> cb.push_back(buff);
> }
>
> // Show elements:
> for(int i = 0; i<(int)cb.size(); i++)
> {
> printf("%d, %d, %s\n", cb[i].user, cb[i].bufferLength, cb[i].vChar);
> }
[...]
> in the second loop I get <null> when I try to print vChar

Of course. You try to output a std::vector through "%s", but a vector
isn't a C-style string. Learn to use C++ facilities:

std::cout << cb[i].user << ", " << cb[i].bufferLength << ", " <<
cb[i].vChar << std::endl;

This doesn't compile either, which is good, because is gives you an
error message, while the same with printf() just silently compiles and
yields undefined behaviour. So compiler-errors are good,
this-just-doesnt-work-and-I-dont-know-why is very bad.

Since you are storing a C-style string in the vector, you can do this to
output the string (works also with printf):
std::cout << &cb[i].vChar[0];

--
Thomas


== 12 of 13 ==
Date: Mon, Jan 25 2010 11:42 am
From: "Alf P. Steinbach"


* Larry:
> "Alf P. Steinbach" <alfps@start.no> ha scritto nel messaggio
> news:hjki9g$rc0$1@news.eternal-september.org...
>> * Larry:
>>> "Alf P. Steinbach" <alfps@start.no> ha scritto nel messaggio
>
>> However, if this is just raw data, consider
>>
>> typedef unsigned char Byte;
>> typedef vector<Byte> ByteVector;
>
> the new struct should look like this:
>
> struct Buffer
> {
> public:
> vector<unsigned char> vuChar;
> int bufferLength;
> int bytesRecorded;
> int user;
> Buffer() : bytesRecorded(0), bufferLength(0), vChar(NULL), user(0) { };
> };

More like


typedef unsigned char Byte;

struct Something
{
vector<Byte> bytes;
int userId;
// Constructor etc.
};

> what the difference between:
> --> vector<unsigned char> vuChar;
> and
> --> unsigne char buffer[]

The declaration

unsigned char buffer[51];

says that 'buffer' is a contiguous area of memory consisting of 51 elements each
of type 'unsigned char'.

The declaration

vector<unsigned char> v( 51 );

says that 'v' is a 'vector' which internally holds a pointer to a buffer, and
that on construction it should create a buffer of 51 elements. This can be
resized (if necessary the vector will discard the original buffer and copy
everything over to a and sufficiently larger buffer). And you can assign to 'v'
and generally copy 'v', and be sure that there is no memory leak.


Cheers & hth.,

- Alf


== 13 of 13 ==
Date: Mon, Jan 25 2010 11:53 am
From: "Larry"


"Thomas J. Gritzan" <phygon_antispam@gmx.de> ha scritto nel messaggio
news:hjkru0$o2i$1@newsreader3.netcologne.de...

>> struct Buffer
>> {
>> public:
>> vector<char> vChar;
>> int bufferLength;
>> int bytesRecorded;
>> int user;
>> Buffer() : bytesRecorded(0), bufferLength(0), user(0) { };
>> };

So I think the following is the only way not to have memory leaks:

#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 Buffer
{
public:
char payload[4096];
int bytesRecorded;
int user;
Buffer() : bytesRecorded(0), user(0) { }
};

int main()
{
circular_buffer<Buffer> cb(numbuff);

// Insert elements
printf("Push elements:\n");
for(int i = 0; i<5; i++)
{
// Get time
char szTime[30]; getDateTime(szTime);

// Init Buff
Buffer buff;
ZeroMemory(&buff, sizeof(Buffer));

memcpy(static_cast<void*>(buff.payload), static_cast<void*>(szTime),
buflen);
buff.user = i;
buff.bytesRecorded = buflen;

cb.push_back(buff);

printf("%s\n", buff.payload);
Sleep(1000);
}

// Show elements:
printf("Show elements:\n");
for(int i = 0; i<(int)cb.size(); i++)
{
printf("%s\n", cb[i].payload);
}

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);
}

where payload is set to 4096 bytes long. Indeed it's going to hold less data
but this way I can make sure it can hold from 0 to 4095 bytes...the other
filed in the struct will store how long payload actually is!

thanks


==============================================================================
TOPIC: ۞_۞free shipping wholesale low price nike shox shoes and ed hardy Jeans
etc (www.ecyaya.com)
http://groups.google.com/group/comp.lang.c++/t/4a1a06e6e0fe3313?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 8:20 am
From: hero


۞_۞free shipping wholesale low price nike shox shoes and ed hardy
Jeans etc (www.ecyaya.com)


Footwear (paypal payment)( www.ecyaya.com )

Paul Smith shoes

Jordan shoes

Bape shoes (paypal payment)( www.ecyaya.com )

Chanel shoes (paypal payment)( www.ecyaya.com )

D&G shoes

Dior shoes (paypal payment)( www.ecyaya.com )

ED hardy shoes

Evisu shoes

Fendi shoes

Gucci shoe (paypal payment)( www.ecyaya.com )

Hogan shoes (paypal payment)( www.ecyaya.com )

Lv shoes

Prada shoes (paypal payment)( www.ecyaya.com )

Timberland shoes

Tous shoes (paypal payment)( www.ecyaya.com )

Ugg shoes

Ice cream shoes (paypal payment)( www.ecyaya.com )
Sebago shoes (paypal payment)( www.ecyaya.com )

Lacoste shoes

Air force one shoes (paypal payment)( www.ecyaya.com )

TODS shoes

AF shoes (paypal payment)( www.ecyaya.com )

cheap EVISU jeans wholesale www.ecyaya.com

cheap ED hardy jeans wholesale

cheap COOGI jeans wholesale www.ecyaya.com

cheap GINO GREEN GLOBAL jeans wholesale

cheap LACOSTE jeans wholesale www.ecyaya.com

cheap G-STAR jeans wholesale www.ecyaya.com

cheap KED ROBOT jeans wholesale

cheap RED MONKEY jeans wholesale www.ecyaya.com

cheap ADIDAS jeans wholesale www.ecyaya.com

cheap BBC jeans wholesale

cheap BOSS jeans wholesale www.ecyaya.com

cheap LRG jeans wholesale

cheap HELEN jeans wholesale www.ecyaya.com

cheap JUICY jeans wholesale

cheap THE CROUN HOLDER jeans wholesale www.ecyaya.com

cheap SMET jeans wholesale www.ecyaya.com

cheap SEVEN jeans wholesale www.ecyaya.com

cheap TRUN NORTH FACE jeans wholesale

cheap children jeans wholesale www.ecyaya.com

cheap ARMANI jeans wholesale www.ecyaya.com

cheap BAPE jeans wholesale

cheap LEVIS jeans wholesale www.ecyaya.com

cheap ANTIK jeans wholesale www.ecyaya.com

cheap true religion jeans wholesale www.ecyaya.com


==============================================================================
TOPIC: Support for export keyword ?
http://groups.google.com/group/comp.lang.c++/t/0878ed0c9c1ca584?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 9:14 am
From: Juha Nieminen


James Kanze wrote:
> But it doesn't solve the problem. You've shown that in one
> simple case it can be made to work. That's not what's required.
> It has to work in all legal cases.

That's why I asked for examples of export templates which are
difficult for compilers to implement. All you have said is that export
templates are difficult, without giving any actual examples.

==============================================================================
TOPIC: std::vector<boost::xpressive::sregex> fails to compile using gcc
http://groups.google.com/group/comp.lang.c++/t/3bb89df1dac2c2c6?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 10:30 am
From: "flewpaul@gmail.com"


On Jan 22, 9:19 am, "flewp...@gmail.com" <flewp...@gmail.com> wrote:
> On Jan 22, 5:41 am, Christophe Bourez <bou...@gmail.com> wrote:
>
>
>
> > On 22 jan, 14:38, Jeff Flinn <TriumphSprint2...@hotmail.com> wrote:
>
> > > flewp...@gmail.com wrote:
> > > > Hi
>
> > > > I'm trying to use a vector of Boost Xpressive sregex objects. VS2005
> > > > compiles my code successfully, but gcc 3.4 and 4.1 fail with:
>
> > > > <path>/include/c++/3.4.5/bits/stl_construct.h: In function `void
> > > > std::__destroy_aux(_ForwardIterator, _ForwardIterator, __false_type)
> > > > [with _ForwardIterator = boost::xpressive::sregex*]':
> > > > <path>/include/c++/3.4.5/bits/stl_construct.h:152:   instantiated from
> > > > `void std::_Destroy(_ForwardIterator, _ForwardIterator) [with
> > > > _ForwardIterator = boost::xpressive::sregex*]'
> > > > <path>/include/c++/3.4.5/bits/stl_vector.h:256:   instantiated from
> > > > `std::vector<_Tp, _Alloc>::~vector() [with _Tp =
> > > > boost::xpressive::sregex, _Alloc =
> > > > std::allocator<boost::xpressive::sregex>]'
> > > > ..\test.cpp:9:   instantiated from here
> > > > <path>/include/c++/3.4.5/bits/stl_construct.h:120: error: no matching
> > > > function for call to `_Destroy(const
> > > > boost::proto::exprns_::expr<boost::proto::tag::address_of,
> > > > boost::proto::argsns_::list1<boost::xpressive::basic_regex<__gnu_cxx::__normal_iterator<const
> > > > char*, std::basic_string<char, std::char_traits<char>,
> > > > std::allocator<char> > > >&>, 1l>)'
>
> > > > The code to generate this is:
>
> > > > #include <vector>
> > > > #include <boost/xpressive/xpressive_dynamic.hpp>
>
> > > > using namespace std;
> > > > using namespace boost::xpressive;
>
> > > > int main(int argc, char* argv[])
> > > > {
> > > >        vector<sregex> vec;
> > > >        return 0;
> > > > }
>
> > > My guess is that sregex is an incomplete type in this context, and IIRC,
> > > std::vector requires complete type for instantiation. Did you mean to
> > > include xpressive_dynamic.hpp? sregex probably is only forward declared
> > > with this include. Did you mean to include xpressive_static.hpp?
>
> > > Jeff
>
> > Hi Jeff,
>
> > In my test, I did
> > #include <boost/xpressive/xpressive.hpp> which includes both dynamic
> > and static.
>
> > Christophe
>
> Thanks for the responses. I'll look at my code to see whether a list<>
> will offer the performance I need in this case. I did cross-post to
> gnu.g++.bug but haven't got any response - I'll post on the Boost list
> aswell.
>
> Many Thanks
>
> Paul

Posted on Boost bug list, turns out it has already been reported and
fixed for Boost 1.42 (https://svn.boost.org/trac/boost/ticket/3712)

==============================================================================
TOPIC: Object (de)serialization
http://groups.google.com/group/comp.lang.c++/t/9fc67e8f28fe4918?hl=en
==============================================================================

== 1 of 5 ==
Date: Mon, Jan 25 2010 11:31 am
From: Philip Pemberton


On Mon, 25 Jan 2010 05:13:01 -0800, Brian wrote:

>> class Triangle : public Shape {
>>         public:
>>                 Triangle() {
>>                         cerr<<"ctor: Triangle\n";
>>                         creationMap["triangle"] = new
>>                         Triangle();
>>                 }
>
> That default constructor looks like trouble. Perhaps you could move the
> second line to another function.

The thing is, I need some way of creating an arbitrary object (in this
case a Shape) based on a given ID string.

Basically, I'm saving objects to/reading objects from a "chunky" file
format (a bit like EA IFF 85). The file is structured into chunks, which
have this format:
4-byte FOURCC (Chunk ID)
8-byte length
Chunk payload
A chunk may have children, in which case the MSBit of the length is set.

What I want is to have as little copy-pasted code as possible, while
still having easy-to-read code. For serialisation, I've got two functions
in Chunk:
vector<uint8_t> Serialise()
virtual vector<uint8_t> SerialisePayload() =0;
(there's also a pure-virtual getChunkID() fn which returns a 4-character
std::string containing the FOURCC code; this is implemented in all child
classes)

Chunk::Serialise calls this->SerialisePayload() to get the payload data,
then outputs the header and payload into a vector and returns it. The
idea being that the headers are common to all chunks, but payload data
depends on the specific class being serialised.

Now back to the deserialisation problem...

At this point I haven't even managed to get an example implementation of
the C++FAQ deserialiser working -- the static ctors aren't being called,
so the std::map doesn't contain anything, thus the code bombs (current
version throws an exception, the one I posted segfaults)...

Thanks,
Phil.


== 2 of 5 ==
Date: Mon, Jan 25 2010 11:33 am
From: Philip Pemberton


On Mon, 25 Jan 2010 10:55:45 +0000, Richard Herring wrote:

> In message <002b5892$0$30072$c3e8da3@news.astraweb.com>, Philip
> Pemberton <usenet09@philpem.me.uk> writes
>>class Shape {
>> public:
>> Shape() { cerr<<"ctor: Shape\n"; };
>> static std::map<std::string, Shape *> creationMap;
>
> That's a declaration. Where's the corresponding definition?
>
> std::map<std::string, Shape *> Shape::creationMap;

*bangs head on desk*

Up until you posted that, I had no idea that static member variables had
to be declared in the implementation... It's so obvious, I can't believe
I missed it...

Thanks!
--
Phil.
usenet09@philpem.me.uk
http://www.philpem.me.uk/
If mail bounces, replace "09" with the last two digits of the current
year.


== 3 of 5 ==
Date: Mon, Jan 25 2010 12:23 pm
From: Brian


On Jan 25, 1:31 pm, Philip Pemberton <usene...@philpem.me.uk> wrote:
> On Mon, 25 Jan 2010 05:13:01 -0800, Brian wrote:
> >> class Triangle : public Shape {
> >>         public:
> >>                 Triangle() {
> >>                         cerr<<"ctor: Triangle\n";
> >>                         creationMap["triangle"] = new
> >>                         Triangle();
> >>                 }
>
> > That default constructor looks like trouble.  Perhaps you could move the
> > second line to another function.
>
> The thing is, I need some way of creating an arbitrary object (in this
> case a Shape) based on a given ID string.
>
> Basically, I'm saving objects to/reading objects from a "chunky" file
> format (a bit like EA IFF 85). The file is structured into chunks, which
> have this format:
>   4-byte FOURCC (Chunk ID)
>   8-byte length
>   Chunk payload
> A chunk may have children, in which case the MSBit of the length is set.
>
> What I want is to have as little copy-pasted code as possible, while
> still having easy-to-read code. For serialisation, I've got two functions
> in Chunk:
>   vector<uint8_t> Serialise()
>   virtual vector<uint8_t> SerialisePayload() =0;
> (there's also a pure-virtual getChunkID() fn which returns a 4-character
> std::string containing the FOURCC code; this is implemented in all child
> classes)

I'm not sure if I'm following you, but the way I do it
a constant for each type being marshalled is output by
a code generator. For your code it would have this:

uint32_t const Shape_num = 7001;
uint32_t const Triangle_num = 7002;


The process of sending an object involves sending
it's "type number" and receiving uses the type
numbers to interpret the input. There's some
related information about this here --
http://webEbenezer.net/release/110.html .
That page describes how I've switched from using
virtual functions like your create to using
"stream" constructors which don't need to be
virtual.


>
> Chunk::Serialise calls this->SerialisePayload() to get the payload data,
> then outputs the header and payload into a vector and returns it. The
> idea being that the headers are common to all chunks, but payload data
> depends on the specific class being serialised.
>

The above sounds somewhat similar to how I do it, but you've
got different terminology. I talk about messages, message
IDs and message lengths. Typically a message id is embedded
first into the stream, then a message length and then the
message/payload.


Brian Wood
http://webEbenezer.net
(651) 251-9384


== 4 of 5 ==
Date: Mon, Jan 25 2010 12:31 pm
From: "Thomas J. Gritzan"


Am 25.01.2010 20:31, schrieb Philip Pemberton:
> On Mon, 25 Jan 2010 05:13:01 -0800, Brian wrote:
>
>>> class Triangle : public Shape {
>>> public:
>>> Triangle() {
>>> cerr<<"ctor: Triangle\n";
>>> creationMap["triangle"] = new
>>> Triangle();
>>> }
>>
>> That default constructor looks like trouble. Perhaps you could move the
>> second line to another function.
[...]
> Now back to the deserialisation problem...
>
> At this point I haven't even managed to get an example implementation of
> the C++FAQ deserialiser working -- the static ctors aren't being called,
> so the std::map doesn't contain anything, thus the code bombs (current
> version throws an exception, the one I posted segfaults)...

The map isn't filled because you don't create triangle, so the line
creationMap["triangle"] = new Triangle();
isn't executed. You have to move this line somewhere else so that it's
invoked before you use creationMap, like a registerShape function
that'll be called from main.

But instead using this prototype based meachanism, I suggest using a
factory functor and storing a boost::function in creationMap, if you
have access to Boost (std::tr1::function is the same). Example:

#include <map>
#include <string>
#include <iostream>
#include <boost/function.hpp>

using namespace std;

class Shape {
public:
Shape() { cerr << "ctor: Shape\n"; };
static Shape* deserialise(string data) {
return creationMap[data]();
}
// add virtual d'tor to allow typeid / delete through base pointer
virtual ~Shape() {}
protected:
typedef boost::function<Shape*()> creation_func;
static void registerShape(std::string type, creation_func factory) {
creationMap[type] = factory;
}

template <typename T>
static Shape* create() {
return new T;
}
private:
static std::map<std::string, creation_func> creationMap;
};

/*static*/ std::map<std::string, Shape::creation_func> Shape::creationMap;

class Triangle : public Shape {
public:
Triangle() {
cerr << "ctor: Triangle\n";
}
static void registerClass() {
registerShape("triangle", &Shape::create<Triangle>);
}
};

int main()
{
Triangle::registerClass();
Shape *x = Shape::deserialise("triangle");

// checks if x has correct type:
cerr << typeid(*x).name() << endl;
delete x;
}

--
Thomas


== 5 of 5 ==
Date: Mon, Jan 25 2010 1:31 pm
From: Branimir Maksimovic


Thomas J. Gritzan wrote:

> class Triangle : public Shape {
> public:
> Triangle() {
> cerr << "ctor: Triangle\n";
> }
> static void registerClass() {
> registerShape("triangle", &Shape::create<Triangle>);
> }
> };
>
> int main()
> {
> Triangle::registerClass();
> Shape *x = Shape::deserialise("triangle");
>
> // checks if x has correct type:
> cerr << typeid(*x).name() << endl;
> delete x;
> }
>

Perfect, I use this method since 1999.

==============================================================================
TOPIC: Memory contents mysteriously changing
http://groups.google.com/group/comp.lang.c++/t/d3d7f50cba06cf27?hl=en
==============================================================================

== 1 of 4 ==
Date: Mon, Jan 25 2010 2:10 pm
From: Mark


On Jan 23, 2:36 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> If you comment out all calls to the library (so that you don't even have
> to link it in), does the corruption happen? If not, it's the library
> and you need to look into getting a different one. If yes, then the
> library has nothing to do with it and you need to start looking at other
> places in your code.

The answer to your question is: yes, when I comment out all calls to
the SILO library, the problem goes away. I guess that's pretty strong
evidence in favor of the library having problems, huh?

BTW, for that reason I tried upgrading to the most recent release of
SILO, but I still have the problem.


== 2 of 4 ==
Date: Mon, Jan 25 2010 2:29 pm
From: Mark


On Jan 23, 11:52 am, LR <lr...@superlink.net> wrote:
> LR wrote:
> > Mark wrote:
>
> Sorry, I forgot to ask about Silo.
>
> Is this a C or a C++ library?
>
> LR


Good question. As best I can tell by looking at the header file it's
a C library that is written to be compatible with C++.

Will I run into memory allocation problems if I mix C and C++? And is
there a way to check whether this is happening?


== 3 of 4 ==
Date: Mon, Jan 25 2010 2:31 pm
From: Mark


On Jan 23, 12:24 pm, Krice <pau...@mbnet.fi> wrote:
> On 22 tammi, 22:46, Mark <markcbaum...@gmail.com> wrote:
>
> > // create the coordinate grid
> > float * xcoords = new float[xgridmax];
> > float * ycoords = new float[ygridmax];
> > float * zcoords = new float[zgridmax];
>
> I didn't see you use delete[] on these ones.


Good catch, thanks. I'll fix that.


== 4 of 4 ==
Date: Mon, Jan 25 2010 2:39 pm
From: Pete Becker


Mark wrote:
> On Jan 23, 2:36 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
>> If you comment out all calls to the library (so that you don't even have
>> to link it in), does the corruption happen? If not, it's the library
>> and you need to look into getting a different one. If yes, then the
>> library has nothing to do with it and you need to start looking at other
>> places in your code.
>
> The answer to your question is: yes, when I comment out all calls to
> the SILO library, the problem goes away. I guess that's pretty strong
> evidence in favor of the library having problems, huh?
>

No, it's not.

> BTW, for that reason I tried upgrading to the most recent release of
> SILO, but I still have the problem.

See? <g>

Memory management problems show up at places that have nothing to do
with the spot where the error actually occurred. And since a memory
management problem typically means that code ends up stomping on memory
that it shouldn't be touching, the effects can seem random. Swapping two
lines of code can make the symptoms disappear; commenting out large
chunks of code can do the same. But often that's just symptoms. The
underlying problem is still there.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: