|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Feb 2001
Messaggi: 75
|
C: Funzione che restituisce la memoria libera??
E' tutto il pomeriggio che cerco una funzione in C che mi restituisce la memoria libera
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Non esiste una funzione standard, e la procedura dipende dal sistema operativo. Sotto windows dovrebbe esserci una API che ora ovviamente non ricordo.
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Per Windows :
Codice:
// Sample output:
// c:\>globalex
// 78 percent of memory is in use.
// There are 65076 total Kbytes of physical memory.
// There are 14248 free Kbytes of physical memory.
// There are 150960 total Kbytes of paging file.
// There are 88360 free Kbytes of paging file.
// There are 1fff80 total Kbytes of virtual memory.
// There are 1fe770 free Kbytes of virtual memory.
// There are 0 free Kbytes of extended memory.
#define _WIN32_WINNT 0x0500
#include <windows.h>
// Use to change the divisor from Kb to Mb.
#define DIV 1024
// #define DIV 1
char *divisor = "K";
// char *divisor = "";
// Handle the width of the field in which to print numbers this way to
// make changes easier. The asterisk in the print format specifier
// "%*I64d" takes an int from the argument list, and uses it to pad
// and right-justify the number being formatted.
#define WIDTH 7
void main(int argc, char *argv[])
{
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
printf ("%ld percent of memory is in use.\n",
statex.dwMemoryLoad);
printf ("There are %*I64d total %sbytes of physical memory.\n",
WIDTH, statex.ullTotalPhys/DIV, divisor);
printf ("There are %*I64d free %sbytes of physical memory.\n",
WIDTH, statex.ullAvailPhys/DIV, divisor);
printf ("There are %*I64d total %sbytes of paging file.\n",
WIDTH, statex.ullTotalPageFile/DIV, divisor);
printf ("There are %*I64d free %sbytes of paging file.\n",
WIDTH, statex.ullAvailPageFile/DIV, divisor);
printf ("There are %*I64x total %sbytes of virtual memory.\n",
WIDTH, statex.ullTotalVirtual/DIV, divisor);
printf ("There are %*I64x free %sbytes of virtual memory.\n",
WIDTH, statex.ullAvailVirtual/DIV, divisor);
// Show the amount of extended memory available.
printf ("There are %*I64x free %sbytes of extended memory.\n",
WIDTH, statex.ullAvailExtendedVirtual/DIV, divisor);
}
Requirements
Windows NT/2000 or later: Requires Windows 2000 or later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
|
|
|
|
|
|
#4 |
|
Bannato
Iscritto dal: Jan 2002
Città: Torino
Messaggi: 1005
|
Non c'è la funzione malloc? Della stlib?
Non ricordo molto bene come funge. E' quasi un anno che ho passato quell'esame! |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
malloc serve per allocare la memoria...non per vedere quanta ce n'è libera...
|
|
|
|
|
|
#6 |
|
Member
Iscritto dal: Feb 2001
Messaggi: 75
|
Intanto grazie a tutti.
Mi scuso per la domanda troppo generica però credevo esistesse una funzione std per risolvere il mio problema. Il programma deve funzionare sotto dos ed utilizza solo memoria convenzionale. Spero possate aiutarmi Grazie |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Con quale compilatore ?
|
|
|
|
|
|
#8 |
|
Member
Iscritto dal: Feb 2001
Messaggi: 75
|
Borland Turbo c++ 3.0
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Hai provato a cercare nell'help ?
memfree, freemem, memused o qualcosa del genere ? |
|
|
|
|
|
#10 |
|
Member
Iscritto dal: Feb 2001
Messaggi: 75
|
Sì, ma non ho trovato nulla. Se vado avanti così entro stasera mi sono letto tutto l'help
|
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Prova con memavail...
|
|
|
|
|
|
#12 |
|
Member
Iscritto dal: Feb 2001
Messaggi: 75
|
Niente. L'unica cosa che ho trovato è biosmemory che restituisce la memoria totale
|
|
|
|
|
|
#13 |
|
Bannato
Iscritto dal: Jan 2002
Città: Torino
Messaggi: 1005
|
Bah, riguardando gli appunti ho usato una cosa della stlib che si chiama free, restituisce la memoria allocata con malloc mi pare, solo che non se ti è utile. (non sono un buon programmatore)!
Ciao! |
|
|
|
|
|
#14 | |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Quote:
Comunque ora che ci penso se il tuo programma è per DOS (e non per Windows) potrai avere al massimo 640Kb di memoria libera...quindi è unitile anche cercare quella funzione... |
|
|
|
|
|
|
#15 | |
|
Bannato
Iscritto dal: Mar 2002
Città: Pescara - 未婚・恋人なし Moto: Honda CBR 1000 RR Casco: XR1000 Diabolic 3
Messaggi: 27578
|
Quote:
|
|
|
|
|
|
|
#16 |
|
Member
Iscritto dal: Feb 2001
Messaggi: 75
|
La funzione mi serve per essere sicuro di rilasciare i puntatori in maniera corretta così da non andare a sovrascrivere parti di memoria già occupate (l'applicazione potrebbe funzionare diversi mesi senza essere rilanciata).
Se il mio dubbio è sbagliato, vi prego di corregermi visto che non conosco molto beneil C ma devo, ale volte, programmarci per lavoro. Grazie |
|
|
|
|
|
#17 | |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Quote:
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
|
#18 | |
|
Bannato
Iscritto dal: Mar 2002
Città: Pescara - 未婚・恋人なし Moto: Honda CBR 1000 RR Casco: XR1000 Diabolic 3
Messaggi: 27578
|
Quote:
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:36.



















