Lowering memory usage by application

topic: 

The working set of a process is the set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. While increasing your working set size can reduce paging for your application, it can adversely affect the system performance.

VFP is know in using all the memory it can get. One of proactive steps in reducing memory usage is limiting VFP buffers size using SYS(3050) - Set Buffer Memory Size. It's a good idea to empty the working set when your application goes into a wait state. It can be done by calling EmptyWorkingSet Function or SetProcessWorkingSetSize Function and uses GetCurrentProcess Function

.

This is sample code. Add error handling and adjust to your requirements as necessary.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18

DECLARE long GetCurrentProcess IN WIN32API
DECLARE Long EmptyWorkingSet IN Psapi.dll Long hProcess
DECLARE long SetProcessWorkingSetSize IN WIN32API Long hProcess, ;
		Long dwMinimumWorkingSetSize, Long dwMaximumWorkingSetSize

IF EmptyWorkingSet(GetCurrentProcess()) <> 0
	* Success
ENDIF

* or

IF SetProcessWorkingSetSize(GetCurrentProcess(), -1, -1) <> 0
	* Success
ENDIF
	
 

Comments

What is the best way to tell if your app has entered a wait state?

Cheers, Keith

Application will be in the wait state when it is waiting for some event, like user input, etc.

Sergey, so is it advisable to put the call
IF EmptyWorkingSet(GetCurrentProcess()) <> 0
* Success
ENDIF
in a control's (textbox, editbox, checkbox, ...) gotfocus()?

Kind regards
Bhavbhuti

No

Thanks Sergey