Thread View: borland.public.cppbuilder.internet.socket
7 messages
7 total messages
Started by tsokas
Tue, 10 Oct 2006 07:25
IdHTTP in a thread crashes when using CodeGuard
Author: tsokas
Date: Tue, 10 Oct 2006 07:25
Date: Tue, 10 Oct 2006 07:25
36 lines
1997 bytes
1997 bytes
Hi all,
I'm trying to use the TIdHTTP component in a thread like this:
void __fastcall TMyThread::Execute()
{
TIdHTTP* HTTP = new TIdHTTP(NULL);
AnsiString dummy = HTTP->Get("http://some_url");
delete HTTP;
}
//---------------------------------------------------------------------------
in main form I use:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TMyThread* thread;
for (int i=0; i<50; i++)
{
thread = new TMyThread();
thread->Resume();
}
}
//---------------------------------------------------------------------------
Then, during runtime (I use CodeGuard) it pops an
EOutOfMemory exception and then it prompts to line "AnsiString dummy =
.......".
Is it some incompatibility between Indy and CodeGuard? Or CodeGuard
just messes
things when going multi-threaded?...
Thanks
Nicolas
Re: IdHTTP in a thread crashes when using CodeGuard
Author: Remy Lebeau (TeamB)
Date: Tue, 10 Oct 2006 08:23
Date: Tue, 10 Oct 2006 08:23
19 lines
1603 bytes
1603 bytes
<tsokas@gmail.com> wrote in message news:1160465153.402484.273810@h48g2000cwc.googlegroups.com... > I'm trying to use the TIdHTTP component in a thread like this: You are not protecting the thread from exceptions. You should wrap the call to Get() in a try..catch or try..finally block, or use the STL's auto_ptr class, to ensure that the TIdHTTP is freed properly even when Get() throws an exception when the download fails. > Then, during runtime (I use CodeGuard) it pops an > EOutOfMemory exception and then it prompts to line "AnsiString dummy = > .......". How much data are you actually downloading from the URL? Gambit
Re: IdHTTP in a thread crashes when using CodeGuard
Author: tsokas
Date: Tue, 10 Oct 2006 08:52
Date: Tue, 10 Oct 2006 08:52
22 lines
2165 bytes
2165 bytes
Hi Remy, thanks indeed for your quick answers... > You are not protecting the thread from exceptions. You should wrap the call > to Get() in a try..catch or try..finally block, or use the STL's auto_ptr > class, to ensure that the TIdHTTP is freed properly even when Get() throws > an exception when the download fails. In fact the code I presented is actually a small project I created just to figure out what is going wrong. The problem appeared in a larger project, in which I do use auto_ptr's and try-catch blocks. The idea is to use 50 or more threads to download chunks of the same file (segmented doanloading) using IdHTTP's ContentRangeStart and ContentRangeEnd facility (the server I'm testing my program against does support this facility). > How much data are you actually downloading from the URL? The file I'm testing the project with is 18MB. Nicolas
Re: IdHTTP in a thread crashes when using CodeGuard
Author: Frank Gruber
Date: Tue, 10 Oct 2006 09:16
Date: Tue, 10 Oct 2006 09:16
14 lines
1426 bytes
1426 bytes
tsokas@gmail.com schrieb: > Then, during runtime (I use CodeGuard) it pops an > EOutOfMemory exception and then it prompts to line "AnsiString dummy = > .......". > > Is it some incompatibility between Indy and CodeGuard? Or CodeGuard > just messes > things when going multi-threaded?... I don't know which version of BCB you are using, however I also experienced problems with CodeGuard and multi-threaded apps in BCB5. Regards Frank.
Re: IdHTTP in a thread crashes when using CodeGuard
Author: tsokas
Date: Tue, 10 Oct 2006 10:15
Date: Tue, 10 Oct 2006 10:15
12 lines
1550 bytes
1550 bytes
> I don't know which version of BCB you are using, however I also > experienced problems with CodeGuard and multi-threaded apps in BCB5. I use BCB 6.0. Yes, I have the impression that this is about CodeGuard and multi-threaded applications... Thanks Frank, Nicolas
Re: IdHTTP in a thread crashes when using CodeGuard
Author: Remy Lebeau (TeamB)
Date: Tue, 10 Oct 2006 17:47
Date: Tue, 10 Oct 2006 17:47
21 lines
1634 bytes
1634 bytes
<tsokas@gmail.com> wrote in message
news:1160470350.947063.299430@b28g2000cwb.googlegroups.com...
> The file I'm testing the project with is 18MB.
That is a LOT of data to stuff into an AnsiString. That is likely the cause
of your problem. Try using a TStream instead, such as a TMemoryStream, for
example:
#include <memory>
void __fastcall TMyThread::Execute()
{
std::auto_ptr<TIdHTTP> HTTP(new TIdHTTP(NULL));
std::auto_ptr<TMemoryStream> Stream(new TMemoryStream);
HTTP->Get("http://some_url", Stream.get());
}
Gambit
Re: IdHTTP in a thread crashes when using CodeGuard
Author: tsokas
Date: Wed, 11 Oct 2006 06:33
Date: Wed, 11 Oct 2006 06:33
37 lines
2404 bytes
2404 bytes
Ο/Η Remy Lebeau (TeamB) έγραψε:
> <tsokas@gmail.com> wrote in message
> news:1160470350.947063.299430@b28g2000cwb.googlegroups.com...
>
> > The file I'm testing the project with is 18MB.
>
> That is a LOT of data to stuff into an AnsiString. That is likely the cause
> of your problem. Try using a TStream instead, such as a TMemoryStream, for
> example:
>
> #include <memory>
>
> void __fastcall TMyThread::Execute()
> {
> std::auto_ptr<TIdHTTP> HTTP(new TIdHTTP(NULL));
> std::auto_ptr<TMemoryStream> Stream(new TMemoryStream);
> HTTP->Get("http://some_url", Stream.get());
> }
>
>
> Gambit
Remy,
I replaced the code in TMyThread with the one above and it keeps on
throwing that EOutOfMemory Exception and prompting at line
HTTP->Get("http://some_url", Stream.get());
Does it run ok at your computer? With CodeGuard on? If so I may have to
reinstall BCB (?).
Thanks,
Nicolas
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads