http://groups.google.com/group/comp.lang.c++?hl=en
comp.lang.c++@googlegroups.com
Today's topics:
* Motivation of software professionals - 9 messages, 8 authors
http://groups.google.com/group/comp.lang.c++/t/21a3fdec4dd53e6a?hl=en
* Loop generates never-ending sockets and threads, need help debugging - 6
messages, 5 authors
http://groups.google.com/group/comp.lang.c++/t/bfb43e94d5fe70d1?hl=en
* ❤~❤~❤ 2010 Cheap wholesale True Relig Jean, Laguna Beach Jean, G-star Jean,
Armani Jean ect at www.rijing-trade.com <Paypal Payment> - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/78edc2eac9d4f289?hl=en
* dedektive , www detektei de , dedektiv , detektivbuero , werkschutz
frankfurt , detektei frankfurt am , detektei auskunftei , detektei
ueberwachung , + + + + +++ DETEKTEIEN DETEKTIVE ONLINE +++ DETEKTEI HAMBURG +++
PRIVATDETEKTIVE +++ + + http:// - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/708c5972da0eb3b7?hl=en
* Incomplete types and std::vector - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/b0741c38fc15b5f7?hl=en
* Google AI Challenge at U of Waterloo - 5 messages, 5 authors
http://groups.google.com/group/comp.lang.c++/t/40f30c405afc24ab?hl=en
==============================================================================
TOPIC: Motivation of software professionals
http://groups.google.com/group/comp.lang.c++/t/21a3fdec4dd53e6a?hl=en
==============================================================================
== 1 of 9 ==
Date: Fri, Feb 5 2010 8:44 am
From: Tom Anderson
On Fri, 5 Feb 2010, Richard Cornford wrote:
> On Feb 5, 11:19 am, Stefan Kiryazov wrote:
>
>> I am doing a research about motivation in software development,
>> the most efficient practices to motivate software engineers,
>> their popularity, etc.
>
> Strange question; the most efficient motivator of professionals is
> money, and money is very popular.
There's a robust body of work that suggests this is very much *not* the
case. Money motivates some people; technical people are more motivated by
interesting work and respect from their colleagues.
tom
--
It is a formal cultural policy to show unreasonable bias towards any
woman who is both attractive and weird.
== 2 of 9 ==
Date: Fri, Feb 5 2010 9:00 am
From: ram@zedat.fu-berlin.de (Stefan Ram)
Stefan Kiryazov <stefan.kiryazov@gmail.com> writes:
>http://ask.wizefish.com/en/MotivationSurvey.aspx
This survey has a strong selection bias:
Real professionals are motivated by the money.
But those motivated by money will not attend
the survey as they are not being paid for it.
== 3 of 9 ==
Date: Fri, Feb 5 2010 9:54 am
From: Branimir Maksimovic
Stefan Kiryazov wrote:
> Hi all,
>
> I am doing a research about motivation in software development, the
> most efficient practices to motivate software engineers, their
> popularity, etc.
News server Im using doesn;t allow cross post without follow up header,
and max crosspost is three newsgroups.
Greets
== 4 of 9 ==
Date: Fri, Feb 5 2010 10:53 am
From: "Saga"
"Stefan Ram" <ram@zedat.fu-berlin.de> wrote in message
news:selection-20100205175941@ram.dialup.fu-berlin.de...
> Stefan Kiryazov <stefan.kiryazov@gmail.com> writes:
>>http://ask.wizefish.com/en/MotivationSurvey.aspx
>
> This survey has a strong selection bias:
>
> Real professionals are motivated by the money.
>
> But those motivated by money will not attend
> the survey as they are not being paid for it.
And those not motivated by money will also not
attend the survey because they'll think it is
offensive, catagorizing them as "non professional"
simply because they are not motivated by money.
Saga
== 5 of 9 ==
Date: Fri, Feb 5 2010 1:39 pm
From: Tom Anderson
On Fri, 5 Feb 2010, Patricia Shanahan wrote:
> That said, by definition professionals are, to some extent, in it for
> the money. If they were not, they would be amateurs as I am now.
Interesting. Do you think that all the non-financial rewards that are
available (if rarely!) in industry are available in academia or on
volunteer projects?
Something i find quite enjoyable, having moved from academia into
industry, is the sense that a project is actually doing something
valuable, something a business thinks is worth money. Work in academia and
the FOSS community can be very interesting, but a lot of it feels like
farting about.
tom
--
I sometimes think that the IETF is one of the crown jewels in all of
western civilization. -- Tim O'Reilly
== 6 of 9 ==
Date: Fri, Feb 5 2010 2:35 pm
From: Jedrin
If money was the only motivating factor wouldn't we all want to be
wall street bankers instead ?
== 7 of 9 ==
Date: Fri, Feb 5 2010 2:45 pm
From: Jorgen Grahn
On Fri, 2010-02-05, Stefan Kiryazov wrote:
> Hi all,
>
> I am doing a research about motivation in software development, the
> most efficient practices to motivate software engineers, their
> popularity, etc.
>
> As a part of the research, I am doing an online survey for software
> engineers and managers in software development. It takes just several
> minutes and filling it is a good opportunity to share your opinion
> about the motivation practices being used in the software industry
> today: [---]
I find it a bit odd that none of the questions had anything to do with
programming, or even technology or creative work in general. They
could have applied equally well to any kind of project-oriented work.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
== 8 of 9 ==
Date: Fri, Feb 5 2010 2:33 pm
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Jedrin (jrubiando@gmail.com) wrote:
: If money was the only motivating factor wouldn't we all want to be
: wall street bankers instead ?
Perhaps we all do - but until we get that chance...
== 9 of 9 ==
Date: Fri, Feb 5 2010 11:39 pm
From: Roedy Green
On Fri, 5 Feb 2010 04:23:41 -0800 (PST), Richard Cornford
<Richard@litotes.demon.co.uk> wrote, quoted or indirectly quoted
someone who said :
>
>Strange question; the most efficient motivator of professionals is
>money, and money is very popular.
That may be a motivator for taking a job, but I suspect is fairly far
down the list for leaving a job.
Leaving motivations might include:
personality conflict
boredom
too much pressure
Personally, the opportunity to do something I had never done before
was always the top priority. Employers usually want people who have
extensive specific experience.
In hiring, my main interest was loyalty. Employees don't get really
useful until after the first year. I don't expect them to hit the
ground running. I anticipate investing considerable effort in training
them. I looked for reasons why they would likely want to stay.
--
Roedy Green Canadian Mind Products
http://mindprod.com
You can't have great software without a great team, and most software teams behave like dysfunctional families.
~ Jim McCarthy
==============================================================================
TOPIC: Loop generates never-ending sockets and threads, need help debugging
http://groups.google.com/group/comp.lang.c++/t/bfb43e94d5fe70d1?hl=en
==============================================================================
== 1 of 6 ==
Date: Fri, Feb 5 2010 9:55 am
From: "Kurt"
Hi all,
I have a client/server project written by a hired contractor, but it's got a fairly big bug when it comes to dealing with thread and sockets. It creates threads but never closes the handle to them, thus causing the server to accumulate hundreds of thousands of open handles in a day or so. The client and server both share similar code, but I'll just post the server-side.
void CTransferServer::startCommandThread() {
int iCommandPort = _wtoi(configHandler->getTextValue(L"TransferCommandPort"));
SOCKET socCommand = CSocHandler::getServerSocket(iCommandPort);
if (socCommand == INVALID_SOCKET) {
//cout << "\nCould not create transfer command server socket." << WSAGetLastError();
return;
}
if (listen(socCommand, SOMAXCONN)) {
//cout << "\nCould not listen on transfer command port." << WSAGetLastError();
return;
}
while (blStarted) {
SOCKET sa = accept(socCommand, 0, 0); // block for connection request
if (sa ==INVALID_SOCKET) {
break;
}
void **params = (void **) malloc(sizeof(void*)*2);
SOCKET *s = new SOCKET;
*s = sa;
params[0] = (void*)this;
params[1] = (void*)s;
DWORD dwGenericThread;
//unsigned int iGenericThread;
HANDLE hWorkerThread = CreateThread(NULL, 0, transferCommandWorkerThread, params, 0, &dwGenericThread);
//HANDLE hWorkerThread = (HANDLE)_beginthreadex(NULL, 0, transferCommandWorkerThread, params, 0, &iGenericThread);
//WaitForSingleObject(hWorkerThread, INFINITE);
//CloseHandle(hWorkerThread);
}
}
DWORD WINAPI transferCommandWorkerThread(LPVOID param) {
void **params = (void **)param;
CTransferServer *transferServer = (CTransferServer*)params[0];
SOCKET *commandSocket = (SOCKET*)params[1];
transferServer->handleCommandConnection(*commandSocket);
delete commandSocket;
free((void*)params);
return 0;
}
So, the while-loop creates a socket that accepts a connection and passes it off to the thread. I am not 100% familiar with sockets and threads, but I have a general idea about them. As far as I can tell, the workerThread does close/delete the sockets properly, but the main loop never closes the handle to the thread. I tried adding WaitForSingleObject() and CloseHandle() but it appears to close the thread prematurely. This causes the communication between the server and client to get disconnected or in a deadlock state. I heard that _beginthreadex() is better to use, but when I tried that, I believe it made matters worse.
Any ideas on how to debug this or perhaps a better way of writing this?
--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
== 2 of 6 ==
Date: Fri, Feb 5 2010 11:10 am
From: Gert-Jan de Vos
On Feb 5, 6:55 pm, "Kurt" <n...@given.com> wrote:
> Hi all,
>
> I have a client/server project written by a hired contractor, but it's got a fairly big bug when it comes to dealing with thread and sockets. It creates threads but never closes the handle to them, thus causing the server to accumulate hundreds of thousands of open handles in a day or so. The client and server both share similar code, but I'll just post the server-side.
>
> void CTransferServer::startCommandThread() {
> int iCommandPort = _wtoi(configHandler->getTextValue(L"TransferCommandPort"));
> SOCKET socCommand = CSocHandler::getServerSocket(iCommandPort);
> if (socCommand == INVALID_SOCKET) {
> //cout << "\nCould not create transfer command server socket." << WSAGetLastError();
> return;
> }
>
> if (listen(socCommand, SOMAXCONN)) {
> //cout << "\nCould not listen on transfer command port." << WSAGetLastError();
> return;
> }
> while (blStarted) {
> SOCKET sa = accept(socCommand, 0, 0); // block for connection request
> if (sa ==INVALID_SOCKET) {
> break;
> }
> void **params = (void **) malloc(sizeof(void*)*2);
> SOCKET *s = new SOCKET;
> *s = sa;
> params[0] = (void*)this;
> params[1] = (void*)s;
> DWORD dwGenericThread;
> //unsigned int iGenericThread;
> HANDLE hWorkerThread = CreateThread(NULL, 0, transferCommandWorkerThread, params, 0, &dwGenericThread);
> //HANDLE hWorkerThread = (HANDLE)_beginthreadex(NULL, 0, transferCommandWorkerThread, params, 0, &iGenericThread);
> //WaitForSingleObject(hWorkerThread, INFINITE);
> //CloseHandle(hWorkerThread);
> }
>
> }
>
> DWORD WINAPI transferCommandWorkerThread(LPVOID param) {
> void **params = (void **)param;
> CTransferServer *transferServer = (CTransferServer*)params[0];
> SOCKET *commandSocket = (SOCKET*)params[1];
> transferServer->handleCommandConnection(*commandSocket);
> delete commandSocket;
> free((void*)params);
> return 0;
>
> }
>
> So, the while-loop creates a socket that accepts a connection and passes it off to the thread. I am not 100% familiar with sockets and threads, but I have a general idea about them. As far as I can tell, the workerThread does close/delete the sockets properly, but the main loop never closes the handle to the thread. I tried adding WaitForSingleObject() and CloseHandle() but it appears to close the thread prematurely. This causes the communication between the server and client to get disconnected or in a deadlock state. I heard that _beginthreadex() is better to use, but when I tried that, I believe it made matters worse.
>
> Any ideas on how to debug this or perhaps a better way of writing this?
Your analysis is correct. This is not very nice C++ code but your
problem can be fixed by using _beginthread() instead of
CreateThread(). This takes care of closing the thread handle at the
end of the thread.
== 3 of 6 ==
Date: Fri, Feb 5 2010 11:15 am
From: Branimir Maksimovic
Kurt wrote:
> Hi all,
>
> I have a client/server project written by a hired contractor, but it's got a fairly big bug when it comes to dealing with thread and sockets. It creates threads but never closes the handle to them, thus causing the server to accumulate hundreds of thousands of open handles in a day or so. The client and server both share similar code, but I'll just post the server-side.
>
....
> while (blStarted) {
> SOCKET sa = accept(socCommand, 0, 0); // block for connection request
> if (sa ==INVALID_SOCKET) {
> break;
> }
> void **params = (void **) malloc(sizeof(void*)*2);
> SOCKET *s = new SOCKET;
> *s = sa;
> params[0] = (void*)this;
> params[1] = (void*)s;
> DWORD dwGenericThread;
> //unsigned int iGenericThread;
> HANDLE hWorkerThread = CreateThread(NULL, 0, transferCommandWorkerThread, params, 0, &dwGenericThread);
> //HANDLE hWorkerThread = (HANDLE)_beginthreadex(NULL, 0, transferCommandWorkerThread, params, 0, &iGenericThread);
> //WaitForSingleObject(hWorkerThread, INFINITE);
> //CloseHandle(hWorkerThread);
> }
> }
>
Hm, what happens if there are more than 1 pending connection requests?
This obviously doesn't work in case of Wait.... since than, no other
connection will be accepted till current client is processed...
Greets
== 4 of 6 ==
Date: Fri, Feb 5 2010 12:39 pm
From: Kurt
On Feb 5, 2:15 pm, Branimir Maksimovic <bm...@hotmail.com> wrote:
> Kurt wrote:
> > Hi all,
>
> > I have a client/server project written by a hired contractor, but it's got a fairly big bug when it comes to dealing with thread and sockets. It creates threads but never closes the handle to them, thus causing the server to accumulate hundreds of thousands of open handles in a day or so. The client and server both share similar code, but I'll just post the server-side.
>
> ....
> > while (blStarted) {
> > SOCKET sa = accept(socCommand, 0, 0); // block for connection request
> > if (sa ==INVALID_SOCKET) {
> > break;
> > }
> > void **params = (void **) malloc(sizeof(void*)*2);
> > SOCKET *s = new SOCKET;
> > *s = sa;
> > params[0] = (void*)this;
> > params[1] = (void*)s;
> > DWORD dwGenericThread;
> > //unsigned int iGenericThread;
> > HANDLE hWorkerThread = CreateThread(NULL, 0, transferCommandWorkerThread, params, 0, &dwGenericThread);
> > //HANDLE hWorkerThread = (HANDLE)_beginthreadex(NULL, 0, transferCommandWorkerThread, params, 0, &iGenericThread);
> > //WaitForSingleObject(hWorkerThread, INFINITE);
> > //CloseHandle(hWorkerThread);
> > }
> > }
>
> Hm, what happens if there are more than 1 pending connection requests?
> This obviously doesn't work in case of Wait.... since than, no other
> connection will be accepted till current client is processed...
>
> Greets
I believe that may be the case as when I have one client transferring
data to the server, another client gets an error. I replaced the
clients with _beginthread() and am waiting for this current transfer
to finish, though I guess this would be a good opportunity to test out
the resume functionality. While on the subject of threads and sockets,
do you have any books to recommend?
Thanks,
Kurt
== 5 of 6 ==
Date: Fri, Feb 5 2010 12:57 pm
From: "Chris M. Thomasson"
"Kurt" <none@given.com> wrote in message
news:zYYan.3749$7S2.796@news.usenetserver.com...
> Hi all,
>
> I have a client/server project written by a hired contractor, but it's got
> a fairly big bug when it comes to dealing with thread and sockets. It
> creates threads but never closes the handle to them, thus causing the
> server to accumulate hundreds of thousands of open handles in a day or so.
> The client and server both share similar code, but I'll just post the
> server-side.
[...]
Have you tried just `CloseHandle()' right after the call to
`_beginthreadex()'? This would be equivalent to creating the thread in a
detached state. You don't need to wait for a detached thread to complete. If
that is not compatible, then you can call `CloseHandle()' right before you
return from the thread entry function. Also, FWIW, you only need
`_beginthreadex()' if the thread uses the CRT...
[...]
== 6 of 6 ==
Date: Fri, Feb 5 2010 1:27 pm
From: Kurt
On Feb 5, 3:57 pm, "Chris M. Thomasson" <n...@spam.invalid> wrote:
> "Kurt" <n...@given.com> wrote in message
>
> news:zYYan.3749$7S2.796@news.usenetserver.com...
>
> > Hi all,
>
> > I have a client/server project written by a hired contractor, but it's got
> > a fairly big bug when it comes to dealing with thread and sockets. It
> > creates threads but never closes the handle to them, thus causing the
> > server to accumulate hundreds of thousands of open handles in a day or so.
> > The client and server both share similar code, but I'll just post the
> > server-side.
>
> [...]
>
> Have you tried just `CloseHandle()' right after the call to
> `_beginthreadex()'? This would be equivalent to creating the thread in a
> detached state. You don't need to wait for a detached thread to complete. If
> that is not compatible, then you can call `CloseHandle()' right before you
> return from the thread entry function. Also, FWIW, you only need
> `_beginthreadex()' if the thread uses the CRT...
>
> [...]
I do not think the projects are using any CRT libraries, at least none
listed here: http://msdn.microsoft.com/en-us/library/abx4dbyh%28VS.80%29.aspx
I did not know that you could run CloseHandle() after creating the
thread, I assumed that it would cause it to stop. The reason I looked
into _beginthreadex() is because I read it was recommended over
CreateThread() due to some known memory leak. I have a few clients
running the beginthread() version, I'll see how it goes over the
weekend and if it doesn't close the threads properly, or causes
issues, I'll try CreateThread()/CloseHandle() in tandem.
Thanks.
==============================================================================
TOPIC: ❤~❤~❤ 2010 Cheap wholesale True Relig Jean, Laguna Beach Jean, G-star
Jean, Armani Jean ect at www.rijing-trade.com <Paypal Payment>
http://groups.google.com/group/comp.lang.c++/t/78edc2eac9d4f289?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Feb 5 2010 10:14 am
From: "www.fjrjtrade.com"
❤~❤~❤ 2010 Cheap wholesale True Relig Jean, Laguna Beach Jean, G-star
Jean, Armani Jean ect at www.rijing-trade.com <Paypal Payment>
Cheap wholesale Jeans
Cheap wholesale A&F Jean
Cheap wholesale Artful Dodger Jean
Cheap wholesale BBC Jean
Cheap wholesale Cavalli Jean
Cheap wholesale Iceberg Jean Man
Cheap wholesale Kanji Jean Man
Cheap wholesale Laguna Beach Jean
Cheap wholesale Michael Jackson Jean Man
Cheap wholesale Prada Jean
Cheap wholesale RMC Jean
Cheap wholesale Robins Jean Man
Cheap wholesale Roca Wear Jean
Cheap wholesale ZEN Jean
Cheap wholesale Affliction Jean
Cheap wholesale Akademiks Jean
Cheap wholesale Armani Jean
Cheap wholesale Bape Jean
Cheap wholesale Christian Audigier Jean
Cheap wholesale Coogi Jean
Cheap wholesale Crown Holder Jean
Cheap wholesale D&G Jean
Cheap wholesale Diesel Jean
Cheap wholesale Ecko Unltd Jean
Cheap wholesale Ed Hardy Jean
Cheap wholesale Evisu Jean
Cheap wholesale G-Star Jean
Cheap wholesale Gucci Jean
Cheap wholesale LEVI'S Jean
Cheap wholesale LRG Jean
Cheap wholesale LV Jean
Cheap wholesale Rock Jean
Cheap wholesale True Relig Jean
Cheap wholesale Versace Jean
More items at website:
http://www.rijing-trade.com
==============================================================================
TOPIC: dedektive , www detektei de , dedektiv , detektivbuero , werkschutz
frankfurt , detektei frankfurt am , detektei auskunftei , detektei
ueberwachung , + + + + +++ DETEKTEIEN DETEKTIVE ONLINE +++ DETEKTEI HAMBURG +++
PRIVATDETEKTIVE +++ + + http://
http://groups.google.com/group/comp.lang.c++/t/708c5972da0eb3b7?hl=en
==============================================================================
== 1 of 1 ==
Date: Fri, Feb 5 2010 12:21 pm
From: herbert mayr
dedektive , www detektei de , dedektiv , detektivbuero , werkschutz
frankfurt , detektei frankfurt am , detektei auskunftei , detektei
ueberwachung ,
+
+
+
+
+++ DETEKTEIEN DETEKTIVE ONLINE +++ DETEKTEI HAMBURG +++
PRIVATDETEKTIVE +++
+
+
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
http://WWW.NBR-DETECTIVE.NL
+
+
+
+
privatdetektiv preise observieren
detektei muelheim detektive
detektivbuero in detektivagentur
detektei ac wachdienst frankfurt
privat ueberwachung detektei usa
www detektiv- tudor com privatdetektiv frankfurt
detektiv tudor detektei tudor
privatdetektiv berlin detektei hannover
privatdetektiv frankfurt privatdetektiv frankfurt
detektei wiesbaden privatdetektive muenchen
den privatdetektiv wirtschaftsdetektei
privatdetektiv gesucht privatdedektiv
weiterbildung frankfurt schulungen frankfurt
==============================================================================
TOPIC: Incomplete types and std::vector
http://groups.google.com/group/comp.lang.c++/t/b0741c38fc15b5f7?hl=en
==============================================================================
== 1 of 3 ==
Date: Fri, Feb 5 2010 1:08 pm
From: Juha Nieminen
Leigh Johnston wrote:
>>
>> I've doubtlessly read it, but I'm not convinced. I repeat: what
>> does std::auto_ptr buy you, compared to a raw pointer?
>>
>
> std::auto_ptr buys you ownership semantics with RAII (no memory leak if
> exception is thrown during construction of class owning the pimpl
> object). The alternative is to write your own version of something
> similar to std::auto_ptr but why bother?
I think that the point is that using std::auto_ptr in the pimpl idiom
doesn't save much work. You still need to write an explicit destructor
(and possibly constructor) and forbid copying and assignment of the
class. Basically you are more or less simply changing a "delete data;"
in the destructor to a "std::auto_ptr" in the class declaration. Not
much of a saving.
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
== 2 of 3 ==
Date: Fri, Feb 5 2010 1:21 pm
From: "Leigh Johnston"
"Juha Nieminen" <nospam@thanks.invalid> wrote in message
news:hki1dc$1jhf$1@adenine.netfront.net...
> Leigh Johnston wrote:
>>>
>>> I've doubtlessly read it, but I'm not convinced. I repeat: what
>>> does std::auto_ptr buy you, compared to a raw pointer?
>>>
>>
>> std::auto_ptr buys you ownership semantics with RAII (no memory leak if
>> exception is thrown during construction of class owning the pimpl
>> object). The alternative is to write your own version of something
>> similar to std::auto_ptr but why bother?
>
> I think that the point is that using std::auto_ptr in the pimpl idiom
> doesn't save much work. You still need to write an explicit destructor
> (and possibly constructor) and forbid copying and assignment of the
> class. Basically you are more or less simply changing a "delete data;"
> in the destructor to a "std::auto_ptr" in the class declaration. Not
> much of a saving.
It is still a saving and saves you from using local (automatic) auto_ptrs in
the constructor body especially if the class has more than one pimpl object
(think about exception safety - a bad_alloc exception could be thrown if you
create more than one pimpl object or anything else that could throw an
exception in the constructor body). "delete data;" in the destructor would
never be called if the constructor body throws an exception.
RAII is one of the features that makes C++ great, not using it is plain
silly.
/Leigh
== 3 of 3 ==
Date: Fri, Feb 5 2010 10:07 pm
From: Joshua Maurice
On Feb 5, 1:21 pm, "Leigh Johnston" <le...@i42.co.uk> wrote:
> "Juha Nieminen" <nos...@thanks.invalid> wrote in message
>
> news:hki1dc$1jhf$1@adenine.netfront.net...
>
> > Leigh Johnston wrote:
>
> >>> I've doubtlessly read it, but I'm not convinced. I repeat: what
> >>> does std::auto_ptr buy you, compared to a raw pointer?
>
> >> std::auto_ptr buys you ownership semantics with RAII (no memory leak if
> >> exception is thrown during construction of class owning the pimpl
> >> object). The alternative is to write your own version of something
> >> similar to std::auto_ptr but why bother?
>
> > I think that the point is that using std::auto_ptr in the pimpl idiom
> > doesn't save much work. You still need to write an explicit destructor
> > (and possibly constructor) and forbid copying and assignment of the
> > class. Basically you are more or less simply changing a "delete data;"
> > in the destructor to a "std::auto_ptr" in the class declaration. Not
> > much of a saving.
>
> It is still a saving and saves you from using local (automatic) auto_ptrs in
> the constructor body especially if the class has more than one pimpl object
> (think about exception safety - a bad_alloc exception could be thrown if you
> create more than one pimpl object or anything else that could throw an
> exception in the constructor body). "delete data;" in the destructor would
> never be called if the constructor body throws an exception.
>
> RAII is one of the features that makes C++ great, not using it is plain
> silly.
My 2 cents: Generally when I use pimpl, it's
//header
#include <string>
class Foo
{
public:
Foo();
~Foo();
std::string getName() const; //ex func
//etc.
private:
class FooImpl;
FooImpl * impl;
};
//cpp
class Foo::FooImpl
{
public:
//impl
};
Foo::Foo() : impl(new Foo::FooImpl) {}
Foo::~Foo() { delete impl; }
std::string Foo::getName() const { /*return impl->getName();*/ return
""; }
//end example
Most uses of pimpl are as simple as this. I would be skeptical of a
design which had "multiple pimpl pointers". The constructor body of
Foo is generally that, no more, no less, give or take the names.
However, I suppose there's nothing to lose by using std::auto_ptr
either.
Finally, I feel stupid. Could someone explain to me how this works,
how std::auto_ptr::~auto_ptr "finds" the name Foo as a complete type?
Probably something to do with template lookup rules, the two phase
lookup, lookup based on instantiation context and declaring context,
and the rest of that nastiness. Playing around with it, I proved to
myself that it does work if Foo::~Foo is defined in a scope where
FooImpl is a complete type, and that it deletes it as an incomplete
type if Foo::~Foo is declared in a different translation unit.
I would think that it would be undefined behavior if Foo::~Foo is
defined in a scope where FooImpl is an incomplete type. Interestingly
enough, if I move the Foo::~Foo definition to before the FooImpl class
definition in the same translation unit, a scope where FooImpl is an
incomplete type, visual studios 2008 still deletes it as a complete
type, which completely mystifies me. Is this visual studios protecting
me from myself, and making it "do the right thing" in a case of
undefined behavior? Or do I completely fail at understanding the
template instantiation and name lookup rules?
I suppose the danger with std::auto_ptr is no greater than the danger
with a naked pointer: you get a delete of an incomplete type pointer
either way, and a good compiler will warn you either way. However,
this just bugs me as questionable style as at the point of declaration
of "std::auto_ptr<Foo::FooImpl> Foo::impl", the type FooImpl is an
incomplete type. That just seems like a bad idea, or something.
Perhaps if I better understood the template magic I would not think
so.
==============================================================================
TOPIC: Google AI Challenge at U of Waterloo
http://groups.google.com/group/comp.lang.c++/t/40f30c405afc24ab?hl=en
==============================================================================
== 1 of 5 ==
Date: Fri, Feb 5 2010 4:02 pm
From: Forthminder
Contest runs from 4 February to 26 February 2010.
You may choose a programming language, such as
Java, C++, Python, Ruby or Haskell.
See details at
http://csclub.uwaterloo.ca/contest/problem_description.php
Bonne Chance!
Mentifex
--
http://www.scn.org/~mentifex/mindforth.txt
== 2 of 5 ==
Date: Fri, Feb 5 2010 4:24 pm
From: "**Group User**"
On Feb 6, 7:02 am, Forthminder <menti...@myuw.net> wrote:
> Contest runs from 4 February to 26 February 2010.
>
> You may choose a programming language, such as
> Java, C++, Python, Ruby or Haskell.
>
> See details at
>
> http://csclub.uwaterloo.ca/contest/problem_description.php
>
> Bonne Chance!
>
> Mentifex
> --http://www.scn.org/~mentifex/mindforth.txt
I find out that
I was a donkie
I was hooked up
Torn
Screwed up
And Haskel was there at that time
He got anrgy, pity
For my stupidity
All for best
Simulation for good alone
KKKKKKIIIIIIIIIIEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEENNNNNNNNNNNNNNNNNNNNNNIIEEEE
== 3 of 5 ==
Date: Fri, Feb 5 2010 7:17 pm
From: Andrej Mitrovic
Sweet, something to keep my brain busy for the next couple of weeks.
== 4 of 5 ==
Date: Fri, Feb 5 2010 7:38 pm
From: John Nagle
Forthminder wrote:
...
Ignore. Well-known nut. See "http://www.nothingisreal.com/mentifex_faq.html"
John Nagle
== 5 of 5 ==
Date: Fri, Feb 5 2010 8:18 pm
From: "Man-wai Chang to The Door (24000bps)"
On 06-Feb-10 08:02, Forthminder wrote:
> Contest runs from 4 February to 26 February 2010.
> http://csclub.uwaterloo.ca/contest/problem_description.php
> Bonne Chance!
It's definitely *not* exactly a programming challenge, but algorithm
challenge.
A programming (only) challenge should only require the players to write
codes to implement an algorithm.
This one requires both algorithm design & programming.
--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.7
^ ^ 12:16:01 up 6 days 20:22 2 users load average: 0.45 0.26 0.09
不借貸! 不詐騙! 不援交! 不打交! 不打劫! 不自殺! 請考慮綜援 (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
==============================================================================
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:
Post a Comment