|
Guys,
Is there any way that we allocate memory using new and do not release it using delete but still prevent memory leakage ??? I've read somewhere that under such cases we should use Smart Pointers to allocate memory, but i was unable to find any sample example to show the usage. If you know the smart pointer solution or any other solution then please tell me.
The reason is that, i've developed a multithreaded application, in which there is a need to terminate threads at an event. But my threads allocate memory using new and whenever a parent thread terminate child thread, there is memory leakage..
|
|
|
|
|
Anonymous wrote:
Is there any way that we allocate memory using new and do not release it using delete but still prevent memory leakage ???
For your example (brutally killing threads that have allocated memory does not do C++ stack unwinding, why smart pointers wouldn't help you) there's but GC. Try googling for "Boehm conservative GC".
|
|
|
|
|
You shouldn't be using TerminateThread() under normal circumstances. It should only be used if the thread has hung, or stuck in an endless loop. As long as it is working normally you can set an Event or use a flag or some other mechanism to ask it to close down normally.
Also as Mike pointed out, smart pointers aren't the solution to this problem. If you want a good set smart pointers for something else, have a look at Boost, http://www.boost.org[^]
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
Hi all,
I'm developing a DirectX Dialog based app using MFC and have run into a problem. I'm using a standard Picture control for my DirectX window. Everything looks great but I can't figure out how to animate in the Picture control window. The first, and only, call to my Render function takes place in the OnPaint() function but, of course, OnPaint() doesn't get constantly called (i.e. only when the app decides it needs repainting).
Does anyone have any ideas on how I can force a repaint (e.g. 30 times/sec)?
Is there a way to repaint just to the Picture control window?
Am I starting off wrong to begin with by using the Picture Control?
Thanks for any help.
|
|
|
|
|
you can get yourself a timer and call InvalidateRect based on the timer u chose, u can use as elapse time 33 millisecs so u get the rate u want.
Better approaches to this is to override the Run function of ur application and call Render there when u have no messages to handle with the elapsed time u want
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I have question about those game trainers for games like Red Alert, Diablo, etc., where it enables you to cheat in the game, such as freezing your money, etc.
So how can i go about finding the memory address of the those variables or values i wish to modifiy?
Weiye, Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
|
Thanks... I'll see if i can understand those assembly stuff...;)
Weiye, Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
Hi.
Is there an object that is part of each item (row) in a CListCtrl that can be used to store arbitrary data or a pointer to them? For example, give there a CListCtrl with two columns. Both columns contain texts; however, I want to store data or pointer to data that correspond to the items in CListCtrl.
I have considered other solutions include an independent STL contains such as a vector that will update as the user makes changes to the CListCtrl. There is a performance reduction for removal. Thus, I that is the last resort.
Thanks,
Kuphryn
|
|
|
|
|
Each item has an LPARAM, which is pointer-sized so you can store a pointer there. If you need data for each column, you'll need to keep a struct or vector or other collection, and hold its address in the LPARAM
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
|
Hello all.
Recently I've encountered the weirdest problem.
In every project i create, all the DDV error messages and all the common messages (i.e. in an SDI/MDI app. instead of seeing "Untitled" at the caption I see some garbage in german), i get in german, or some other language, and not in english.
I've checked all the project resource files and made sure that the language is English u.s., and even under the resource tab in the project settings i've made sure that the language is english u.s., but still, all the messages are in difference language (even in CFileDialog, instead of Open, and All files for example, i get weird language).
Any ideas ?
Help will be appreciated...
|
|
|
|
|
I had a similar problem recently on NT4, my keyboard changed to German layout from UK English. German had been set as an "input locale", but I was using my default, English, my only "cure" was a reboot I assumed something had screwed up the PC.
The obvious question, if you run the code onto another PC what happens
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Two questions - the shorter one first.
When a compiler informs you
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
just how much of a performance hit are we talking about?
Second (the biggie)
In the following code excerpt (which is located in the OnDraw method of an MDI app)
// Fill the client area with black
pDC->FillRect(&rcScreen, &backgroundBrush);
// preserve the aspect ratio
CRect NewPictRect = m_pDIBBitmap->CalcAspectRatio(Rect, TRUE);
// get the bitmap
BITMAP bm;
GetObject(hBmp, sizeof(BITMAP), &bm);
// prepare the bitmapinfo structure
BITMAPINFO bmInfo;
memset(&bmInfo.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth = m_pDIBBitmap->GetBitmapWidth(hBmp);
bmInfo.bmiHeader.biHeight = m_pDIBBitmap->GetBitmapHeight(hBmp);
bmInfo.bmiHeader.biPlanes = 1;
bmInfo.bmiHeader.biBitCount = 24;
////////////////****CUT HERE****////////////////////
// creates the memory dc
HDC TmpDC = CreateCompatibleDC(NULL);
// create bitmap and select into the mem dc
BYTE *pbase;
HBITMAP TmpBmp = CreateDIBSection(TmpDC, &bmInfo, DIB_RGB_COLORS, (void**)&pbase, 0, 0);
// select the object into the current dc
HGDIOBJ TmpObj = SelectObject(TmpDC, TmpBmp); // TmpDC is the dc to draw lines, text, etc...
// draw the background
HDC dcBmp = CreateCompatibleDC(TmpDC);
SelectObject(dcBmp, hBmp);
BitBlt(TmpDC, 0, 0, m_pDIBBitmap->GetBitmapWidth(hBmp), m_pDIBBitmap->GetBitmapHeight(hBmp),
dcBmp, 0, 0, SRCCOPY); // Destination DC first, then source DC
DeleteDC(dcBmp);
// Clean up
DeleteObject(hBmp);
hBmp = TmpBmp;
SelectObject(TmpDC, TmpObj);
DeleteDC(TmpDC);
////////////////*****END CUT HERE*****//////////
m_pDIBBitmap->DrawBitmap(pDC, hBmp, pPal, NewPictRect, Rect);
If I remove the code between the //////////***CUT HERE***///
bits, there is a significant decrease in redrawing speed. Note, however, that the call to DrawBitmap (m_pDIBBitmap->DrawBitmap(pDC, hBmp, pPal, NewPictRect, Rect) ALSO draws the bitmap, independent of the code between the CUTS...
Thus, if I remove the code between the cuts, the bitmap draws fine, but SLOW. If I keep the code the bitmap draws fine but FAST. Can't say I have figured out what is going on here. I seemed to have stumbled upon it inadvertently.
Any input appreciated...
|
|
|
|
|
John Theal wrote:
warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
just how much of a performance hit are we talking about?
I can't imagine much. If you were to do it in C it would be something like bool bWha = !(!nWha); . As with everything, if performance is an issue, then profile your code and find the bottlenecks; otherwise don't worry about it.
John Theal wrote:
Second
Looks like you're trying to do some double buffering here? You can speed it up a lot by NOT creating the back buffer each time you draw; just (re)create it whenever the size changes, and re-use it otherwise. Also, you can't delete a bitmap while it's selected in a DC.
---
Shog9
The siren sings a lonely song - of all the wants and hungers
The lust of love a brute desire - the ledge of life goes under
|
|
|
|
|
I am doing some double-buffering in OnDraw(). There is also some double-buffering going on in DrawBitmap(). However, I have accidentally noticed that Blitting to the TmpDC, then releasing the handle (hBmp) and finally, setting the handle (hBmp) to TmpDC speeds things up incredibly for some reason.
It is rather odd. I suppose I could not re-create the back-buffer each time, but the app is such that the user can drag the frame of the MDI window and enlarge/decrease the size of the bmp at any time - so it sort of needs to happen that way. Anyways, the speed really isn't a problem at this point. I would just like to know *why* this is occuring...
|
|
|
|
|
Ah, sorry - i misunderstood. I'm not sure why this would be faster, unless the original bitmap is in a different format than the screen and the conversion is performed slowly by DrawBitmap().
---
Shog9
The siren sings a lonely song - of all the wants and hungers
The lust of love a brute desire - the ledge of life goes under
|
|
|
|
|
Hello I am trying to use the API function CopyFileEx() however I want my application to run on Windows 95 and this function is not implemented on that system
I cannot even include the function in an IF statement and get the application to run on 95. Something about the kernel32.dll does not export the function.
Is there any easy way to take care of this? Or is the only way to manually do the LoadLibrary, GetProcAddress, AND define a custom variable type? The last one is the worst.
I am really hoping for some answers that I could expand to all functions that I want to use from the newer Windows versions.
Thanks
Nathan Brown
|
|
|
|
|
GetProcAddress is about the only way you can do it. Also, since we are talking about KERNEL32.DLL, a GetModuleHandle will be good enough. You won't have to worry about using FreeLibrary (???) with GetModuleHandle.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
What about the requirement of defining a custom variable type? Is there any way to use the fact that it is already defined in the SDK?
I tried using something like this:
CopyFileExA ProcAdd;
ProcAdd = (CopyFileExA)GetProcAddress(hinstLib, _T("CopyFileEx")); But it didn't work.
Nathan Brown
|
|
|
|
|
Look up the API in MSDN and copy its prototype into your code (adding the WINAPI calling convention). So for CopyFileEx() you'd do:
typedef BOOL (WINAPI* PFN_COPYFILEEX)(LPCTSTR, LPCTSTR, LPPROGRESS_ROUTINE, LPVOID, LPBOOL, DWORD);
PFN_COPYFILEEX pfnCopyFileEx;
(FARPROC&) pfnCopyFileEx = GetProcAddress ( hinst, "CopyFileExA" ); The parameter list is copied straight off the MSDN page. (I think I have the typedef right, I always forget on which side of the * the calling convention goes.)
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Thanks for the help.
Nathan Brown
|
|
|
|
|
How I can get line number of my crash in Release. My project have some DLLs.
Georgi Georgiev.
|
|
|
|
|
I can't figure out a way to have a CListCtrl, showing checkboxes in the leftmost column, enabled but read-only. Meaning, the vertical scrollbar should still work, but the checkboxes cannot be changed.
I understand about faking it (ownerdraw, ignore clicks and keystrokes, etc), but I wonder if there is a standard way for this?
TIA,
Bernd
|
|
|
|
|
This is a confusing issue for me. I think its very relevant to note that this is a dynamically created combobox in a CtoolBar derived class..
I am dynamically doing a Create() to make a combobox in a toolbar. I want to trigger a certain function when I dblclick on a list item of the combobox. How do I set this up? What all do I need to add to my code and where? I gave the toolbar spaceholder button an Id of ID_COMBO1 where its supposed to put in the combobox. In the Class wizard this ID has the COMMAND available but the OnCommand function it made doesnt tell me which item in the list I clicked> Actually what exactly is the COMMAND thing here? In a button when you press it , the commnad handler runs. WHen does the commnad handler run for a combobox? I also guess that you can trap the CBN_DBLCLK message but dont know how to do that . If I can run a handler when this message is trapped, the function that runs can check on the index of the item clicked and do something specifically index-related. SO the index must be passed into the handler. Which class will trap this message and how do I do it in code? In the class wizard I didnt see CBN_DBLCLK. (I am sorry I might be looking in the wrong places... )
In one sample I saw they had : BOOL CToolBarWithCombo::OnCommand(WPARAM wParam, LPARAM lParam) for a toolbar derived from CToolbar. I dont see how to add this function through the class wizard. iN the code it says:
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
so its been done through CW . But how ? Theres no ID_TOOLBAR that I can create a Command handler for...
How do you add a COMMAND handler for a toolbar and after d oing so, how do you set it up to tell you that item number n in the list (ot text "abc" in the list) was pressed in the combobox?
My goal is to make a specific function run when i press an item in the list of my combobox, which is created dynamically, and embedded in a CTOolBAr class .
Appreciate your help,
ns
|
|
|
|
|