Optimisation dun prog. dans la ram (Conseil)

ELCouz Messages postés 135 Date d'inscription jeudi 22 mars 2007 Statut Membre Dernière intervention 25 juillet 2008 - 29 mai 2007 à 00:24
 Utilisateur anonyme - 29 mai 2007 à 14:40
Bonjour,

J'ai denicher ce bout de code sur internet il y a longtemps...
J'ai tester sur un de mes program qui au depart prennais 20mb de ma ram...
et maintenant en utilise que 500k !!! je doute que se soit trop beau pour etre vrai ?!?!
es-ce un bon code pour optimiser la taille du programme dans la memoire ??

SetProcessWorkingSetSize(GetCurrentProcess, $ffffffff, $ffffffff);

jai mit sa dans un timer a toute les 10 secondes la taille du programme reste entre 450k et 700k comparativement a 20mb et 25mb...

Merci!

Laurent

7 réponses

Utilisateur anonyme
29 mai 2007 à 08:51
Salut,

Voila ce que l'on peut lire sur la MSDN :

SetProcessWorkingSetSize
<!--Content type: PSDK_1. Transform: psdk2mtps.xslt.-->
Sets the minimum and maximum working set sizes for the specified process.

BOOL WINAPI SetProcessWorkingSetSize(
HANDLE hProcess,
SIZE_T dwMinimumWorkingSetSize,
SIZE_T dwMaximumWorkingSetSize
);

Parameters
* hProcess :
[in]
A handle to the process whose working set sizes is to be set.

The handle must have the PROCESS_SET_QUOTA access right. For more information, see
GetLastError to obtain extended error information.

Remarks
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.
The minimum and maximum working set sizes affect the virtual memory
paging behavior of a process.

The working set of the specified
process can be emptied by specifying the value (SIZE_T)-1 for both the
minimum and maximum working set sizes. The pages are removed from the
caller's working set. If there are no other processes that are mapping
these pages, then they become candidates to be written to backing
store. If a pages is still mapped by another process, the page is not
written to the backing store until it is unmapped or trimmed from the
working set of each mapping process.

If the values of either dwMinimumWorkingSetSize or dwMaximumWorkingSetSize
are greater than the process' current working set sizes, the specified
process must have the SE_INC_WORKING_SET_NAME privilege. All users
generally have this privilege. For more information about security
privileges, see Privileges.

Windows Server 2003 and Windows XP/2000:  The
specified process must have the SE_INC_BASE_PRIORITY_NAME privilege.
Users in the Administrators and Power Users groups generally have this
privilege. The operating system allocates working set
sizes on a first-come, first-served basis. For example, if an
application successfully sets 40 megabytes as its minimum working set
size on a 64-megabyte system, and a second application requests a
40-megabyte working set size, the operating system denies the second
application's request.

Using the
SetProcessWorkingSetSize function to set an application's
minimum and maximum working set sizes does not guarantee that the
requested memory will be reserved, or that it will remain resident at
all times. When the application is idle, or a low-memory situation
causes a demand for memory, the operating system can reduce the
application's working set. An application can use the VirtualLock
function to lock ranges of the application's virtual address space in
memory; however, that can potentially degrade the performance of the
system.

When
you increase the working set size of an application, you are taking
away physical memory from the rest of the system. This can degrade the
performance of other applications and the system as a whole. It can
also lead to failures of operations that require physical memory to be
present; for example, creating processes, threads, and kernel pool.
Thus, you must use the SetProcessWorkingSetSize function carefully. You must always consider the performance of the whole system when you are designing an application.

Requirements
Client |Requires Windows Vista, Windows XP, Windows 2000 Professional, or Windows NT Workstation 3.5 and later., ----
Server |Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 3.5 and later., ----
Header |Declared in Winbase.h; include Windows.h., ----
Library |Use Kernel32.lib., ----
DLL |Requires Kernel32.dll.
See Also
GetProcessWorkingSetSize
Process and Thread Functions
Process Working Set
Processes
SetProcessWorkingSetSizeEx
VirtualLock
0
ELCouz Messages postés 135 Date d'inscription jeudi 22 mars 2007 Statut Membre Dernière intervention 25 juillet 2008
29 mai 2007 à 09:09
je sais javais deja lu sur msdn mais sa parle si on augmente la taille allouer ,,, sa ne parle pas dici dans ce cas si ... de trimmer lutilisation de la memoire ,,, si cest correct ...
0
cs_Loda Messages postés 814 Date d'inscription vendredi 3 novembre 2000 Statut Membre Dernière intervention 30 juillet 2009 3
29 mai 2007 à 10:04
"This essentially swaps the process out of physical RAM memory"

enfin, c'est ce que je comprend d'après la doc.

après, tu devrais te renseigner sur les algo de gestion de page:
http://en.wikipedia.org/wiki/Page_replacement_algorithm#Working_Set

bon code,

Loda
Se poser les bonnes questions est le premier pas pour trouver les bonnes réponses.
0
ELCouz Messages postés 135 Date d'inscription jeudi 22 mars 2007 Statut Membre Dernière intervention 25 juillet 2008
29 mai 2007 à 10:22
"This essentially swaps the process out of physical RAM memory"



hmmm alors c'est pas vrm une optimisation... sa peu rendre les choses pires surtout que la memoire virtuelle est bcp plus lente ... et certains meme la desactive (dont moi ,,, mais pas sur cette ordinateur que je travail presentement ,,, jvais assayer sur un autre ordi , jsuis curieux de voir le resultat. Probablement un crash ... donc pas bon du tout !!)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
29 mai 2007 à 13:04
20Mo en ram c'est pas grand chose, c'est pas le processus qu'il faut optimiser c'est plutot ton interface et ton code.

tu peu même faire ton propre systeme de cache disque pour certaines données, avec un simple TFileStream.

0
ELCouz Messages postés 135 Date d'inscription jeudi 22 mars 2007 Statut Membre Dernière intervention 25 juillet 2008
29 mai 2007 à 13:14
en faite, faudrais optimiser iexploder (Twebbrowser, eh oui jlaime pas mais quand on a pas lchoix on a pas lchoix ) mdr !! cest lui qui tire toute la ram
ou en refaire un «from scratch»

Laurent
0
Utilisateur anonyme
29 mai 2007 à 14:40
Une autre solution consiste à faire ton propre navigateur : IdHTTP et HMTLLite devrait pouvoir faire l'affaire (mais bon il faut se taper le code en plus ).
0
Rejoignez-nous