Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory Allocation for a Function? 1

Status
Not open for further replies.

Saul775

Programmer
Aug 9, 2004
11
US
Is it possible to allocate memory for a function? I'm running a program that consumes massive amounts of memory. I'm also interfacing with this program and checking various states of the program. After the program reaches a specific state, I exit my message loop and destroy my interfacing window through DestoryWindow(). I then proceed to close the memory-intensive program by looping. Here's the gist...

Code:
HWND hWndToClose = NULL;

while (!hWndToClose)
{
  hWndToClose = FindWindowEx(NULL, NULL, "Class", "Title");
}

PostMessage(hWndToClose, WM_COMMAND, 0x5, 0x0); // File -> Exit

HWND hWndConfirmClose = NULL;

while (!hWndConfirmClose) // Pops up a MessageBox, asking
                          // for me to confirm exiting
{
  hWndConfirmClose = FindWindowEx(NULL, NULL, "Class", "Close?");
}

HWND hWndYes = NULL;

while (!hWndYes)
{
  hWndYes = FindWindowEx(NULL, NULL, "Class", "\&Yes");
}

SendMessage(hWndConfirm, WM_COMMAND, MAKELONG(hWndYes, BN_CLICKED), (LPARAM)hWndYes);

Again, this code will work as long as the computer has not been on for a while, running the memory-intensive program. However, if it has been running the memory-intensive program, this code seems to not exist, and this code does not terminate the memory-intensive program -- even with the loops. That's why I added the loops. I thought they might not have been loaded, but it doesn't seem to matter.

Also, I know I'm consuming a lot of memory as when the computer has been running the memory-intensive program for thirty minutes or so, I receive a message that Windows has adjusted the virtual memory. That's why I'm asking if it's possible to set aside memory for this function. I'm thinking this is my problem.

Again, it seems that if the memory-intensive program has been running for about 30 minutes, my program will terminate the other program. However, if it exceeds thirty minutes, my program seems to stop at the point where I DestroyWindow(MyProgramWindow). I've even added MessageBoxes on the other side of the code, and they don't even appear! My program just seems to terminate nicely, for it's no longer running in the taskmgr. *shrugs*

Any ideas and suggestions into tackling this problem would be much appreciated. Thank you.
 
If you want some functions to be in memory only when needed you should put them in a DLL. However, if your program is continuously eating more and more memory, I'd say you've probably got a memory leak and you need to fix that first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top