|
One more question about this topic.
Where and how should the pointer 'objMyClass' be deleted to prevent memory leak. I think this should be done at the end of SubFunc(). However, I am not very sure.
|
|
|
|
|
cy163@hotmail.com wrote: Where and how should the pointer 'objMyClass' be deleted to prevent memory leak.
Any time after the pObject->SubFunc() call (obviously)
There's alot of people who object to deleting objects in a different thread than the thread the
object was created in. If you are using new/delete this is perfectly legal to do, so IMO it
comes down to preference.
If it's clear in the code that you create an object (using new) and send it off to a worker
thread to be processed, and that the worker thread will delete it when it's finished, then delete
it in the thread proc when you're finished with it.
If you want to delete it in the same thread it was created in (the UI thread in your example)
then you could use PostThreadMessage() from the worker thread to send the pointer back to the UI
thread for deletion when it's finished with it. The worker thread would need to know which thread
it came from to know where to post the message to.
cy163@hotmail.com wrote: I think this should be done at the end of SubFunc(). However, I am not very sure.
I personally wouldn't do it IN the SubFunc() function. That would be, IMO, too buried to be clear
in the code what's going on. Right after the pObject->SubFunc() call a "delete pObject;" would
be fine.
I would just make sure to document it well in the code with comments so when you possibly enhance
the code later you know exactly where objects are bing deleted, something like this:
void CHhhhView::OnButton1()
{
MyClass *objMyClass = new MyClass;
AfxBeginThread(MyThreadProc, objMyClass);
}
Whatever it takes to make sure you always know that you shouldn't use objMyClass later because
at any time the worker thread will delete it
|
|
|
|
|
Thank you Mark for your clear explanation.
One more further question, also about mem leak. i have some dynamically allocated variables (using malloc(), new) in SunFunc(). I wonder if those allocated mem can be deallocated automatically after the thread finished successfully. Or, i have to take care of the memory releasing things myself.
Moreover, could you please talk about how to terminate the thread before SubFunc() reaches its end in my example. I refer to some articles. They suggested to use CEvent and WaitForSingleObject(), as well as AfxEndThread().
I do not how to combine them to terminates a thread from another thread (main thread, in my case).
Thank you for your valuable time
-- modified at 6:10 Monday 6th November, 2006
|
|
|
|
|
Hi,
I want to create a child window with menu like in a SDI application from a dialog based application. How to create it?
Cyber Friend
|
|
|
|
|
Is it possible to reallocate using operator new?
// C
some_ptr = malloc( sizeof( some_type ) * n );
... // change "n"
some_ptr = realloc( sizeof( some_type ) * n );
// C++
some_ptr = new some_type[n];
... // change "n"
// Now what?
Best regards
hint_54
|
|
|
|
|
The short answer is no. Either use a combination of malloc and realloc as in your example, or use the keyword new and copy the contents over to a larger buffer.
|
|
|
|
|
|
Use an STL collection such as vector , and you won't have to worry about the memory allocation.
|
|
|
|
|
Hi
I need a program that convert date to shamsi
thank you
|
|
|
|
|
|
is it possible to get file size if it is opened with fopen_s function?
|
|
|
|
|
You may use fseek() to go the end of the file, and use ftell() to get file current position, which is now also the file size.
|
|
|
|
|
Once you have opened your file:
long size;
fseek(file,0,SEEK_END);
size = ftell(file);
rewind(file);
|
|
|
|
|
Hi,
In my application I created a wmv movie form 3 images. It also have the audio for 15 seconds. Audio per frame is variable means that we can have audiofor first frame for 2 sec , for second frame 10 sec and for 3rd frame 3 sec.
How can I achive this?
one solution can be variable frame rate for each frame. CAn we do this in wmv ? How can we do this? Is there any other alternative available to achive this
All help and guidelines are welcome
Thanks in advance
Regards,
Hemant.
|
|
|
|
|
Can't you keep a constant frame rate?
In your case one frame-per-second would work. So when you write the video stream you'd write
2 frames of the first image, 10 frames of the second image, and 3 of the third image.
Are you using a Video Image stream or a regular video stream for your wmv file?
|
|
|
|
|
What is difference between "Video Image stream" and "regular video stream"?
|
|
|
|
|
A video image stream is made up of still images. The stream is written differently than
regular "live" video when using the windows media sdk to write wmv files.
|
|
|
|
|
Hi,
I am creating a movie from some images it is not a real time video.
My important question is How I can write a metatdata >64 to wmv file?
Regards,
Hemant
|
|
|
|
|
Dear all
I need to know which DMA line is assigned to the parallel port of system in Visual C++ environment.
May you Please Help me.
Regards
Mahdi
|
|
|
|
|
I have added a menu item to the shellcontext menu using shell extensions(ATLCOM AppWizard).When i select the item some operation will be performed.Now i want to attach this feature to an SDI application i.e,when the SDI application is runned this menu item should be inserted to the shell context menu automatically .Any article based on the above problem will be of more help.So,how can i add these two applications into a single application.
Thanks.
|
|
|
|
|
hi,
i created a control then i want to navigate the url but i am getting this error
RECT rectClient;
GetClientRect(&rectClient);
// create the control window
// AFX_IDW_PANE_FIRST is a safe but arbitrary ID
if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, L"Browser",
WS_VISIBLE | WS_CHILD,
rectClient, this,
AFX_IDW_PANE_FIRST))
{
DestroyWindow();
return FALSE;
}
// Get interface pointer
LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2,
(void**) &m_pBrowserApp);
if (!SUCCEEDED(hr))
{
m_pBrowserApp = NULL;
m_wndBrowser.DestroyWindow();
DestroyWindow();
return FALSE;
}
Nav2URL(L"http://www.yahoo.com/");
}
application exist by giving following messages
Load module: browsres.96.dll
Persistence not supported on OLE control {F5AFC7EF-1571-48B6-A69C-F1833F4C3A44}.
>>> Result code: 0x00000000
Load module: webview.dll
Load module: shlwapi.dll
Load module: wininet.dll
Load module: urlmon.dll
Warning: constructing COleException, scode = DISP_E_MEMBERNOTFOUND ($80020003).
RaiseException: Thread=9663ba08 Proc=814c6f20 'TestPcBrowser.exe'
AKY=00004001 PC=03fa27d8(coredll.dll+0x000427d8) RA=800773f4(NK.EXE+0x000073f4) BVA=00000000 FSR=00000000
Warning: constructing COleException, scode = DISP_E_MEMBERNOTFOUND ($80020003).
RaiseException: Thread=9663ba08 Proc=814c6f20 'TestPcBrowser.exe'
AKY=00004001 PC=03fa27d8(coredll.dll+0x000427d8) RA=800773f4(NK.EXE+0x000073f4) BVA=00000000 FSR=00000000
Warning: constructing COleException, scode = DISP_E_MEMBERNOTFOUND ($80020003).
RaiseException: Thread=9663ba08 Proc=814c6f20 'TestPcBrowser.exe'
AKY=00004001 PC=03fa27d8(coredll.dll+0x000427d8) RA=800773f4(NK.EXE+0x000073f4) BVA=00000000 FSR=00000000
Warning: constructing COleException, scode = DISP_E_MEMBERNOTFOUND ($80020003).
RaiseException: Thread=9663ba08 Proc=814c6f20 'TestPcBrowser.exe'
AKY=00004001 PC=03fa27d8(coredll.dll+0x000427d8) RA=800773f4(NK.EXE+0x000073f4) BVA=00000000 FSR=00000000
The thread 0x3675a88a has exited with code 0 (0x0).
venu
|
|
|
|
|
what is .net framework
qwd
|
|
|
|
|
|
Just woke up from hibernation ? , welcome back.
:Gong: 歡迎光臨 吐 西批 :Gong:
|
|
|
|
|
Hi.
I need to pass parameters to sub fuction. it is surely easy. but,
when it comes to variable parameter.. how can I do that?
for example,
void MyPrintf(char * msg, ...)
{
printf(msg ,????); // <- here
// something extra
}
thanks in advance.
|
|
|
|