|
From: Ian W. <lak...@ho...> - 2001-12-05 17:11:20
|
Hello everybody. i was wondering, does anyone know the code that will count the amount of memory in you PC. thanks in advance to anyone that can help. _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp |
|
From: Javier T. <jav...@ci...> - 2002-07-04 05:04:31
|
Hello!=20 Does somebody know of a library to use with dev-c++ to control what is going on with the memory?=20 I mean that I want to know how much memory=20 I use for my variables and pointers, and at the end of my program I must know if all the memory I asked for,=20 has been freed. Thanks. Javier from Argentina |
|
From: Robson B. <rob...@su...> - 2003-03-01 14:46:38
|
Hi coders, I have a question that does not want to shut up! When i code a program, do i have to delete all variables before exiting the main function or does the operating system cares of free all the memory allocated? If i do not delete the variables before main function and use the program several times, may it cause the system memory to be unavailble? Any input welcome! Thanks! |
|
From: <rol...@mi...> - 2003-03-01 15:12:46
|
- variables allocated in stack must not (should not ) be deleted
- variables allocated with new och malloc must be free'd
void main( void )
{
int a ; // allocated on stack - no delete!
int* b = new int ; // allocated with new - do delete!
a = 10 ;
*b = 10 ;
...
...
delete b ; // free b!
}
----- Original Message -----
From: "Robson Bernard" <rob...@su...>
To: "C++ Mail List" <dev...@li...>
Sent: Saturday, March 01, 2003 3:47 PM
Subject: [Dev-C++] Memory
> Hi coders,
>
> I have a question that does not want to shut up! When i code a program, do
i
> have to delete all variables before exiting the main function or does the
> operating system cares of free all the memory allocated? If i do not
delete
> the variables before main function and use the program several times, may
it
> cause the system memory to be unavailble?
>
> Any input welcome!
>
> Thanks!
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Per W. <pw...@ia...> - 2003-03-01 15:54:28
|
For just about all OS, the memory allocated by malloc and new will be released by the OS uppon program termination, i.e. you don't need to release it. However, there are a number of reasons for releasing it anyway: - A debug build may then check for unreleased memory, and can inform you about any memory leaks. A single variable living through the whole program isn't considered a leak. However a buffer that the application should allocate/reallocate regularly during normal operation, and that isn't deallocated is a leak, i.e. while the same instance of the program continues running, the needed memory continues to grow. - When programming in C++, the destructor run when you release your class objects might have other side effects. It might change current mouse cursor, perform flush on file system, remove temporary files, close down a non-standard graphics mode etc. - If all allocated memory gets released when not needed anymore, it is easier to look at the code and determine the useful lifespan of the different variables. There isn't any use to add code to keep a structure up to date, if nobody will ever check the values of the structure anymore. - To support code reuse. What might be a standalone program now, might very well become a sub-module in a larger project tomorrow, and then you don't want to have to pick the code to pieces to get it working. I have probably missed a couple of really important reasons but yes, i'd suggest that you try and release all malloc/calloc/new memory before ending the program, or preferably as soon as you know that you will not need the information anymore. /Per W On Sat, 1 Mar 2003, Robson Bernard wrote: > Hi coders, > > I have a question that does not want to shut up! When i code a program, do i > have to delete all variables before exiting the main function or does the > operating system cares of free all the memory allocated? If i do not delete > the variables before main function and use the program several times, may it > cause the system memory to be unavailble? > > Any input welcome! > > Thanks! > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ho...> - 2003-03-01 16:09:18
|
-------Original Message-------=0D =0D From: Robson Bernard=0D Date: =D3=DC=E2=E2=E1=F4=EF, 1 =CC=DC=F1=F4=E9=EF=F2 2003 4:50:31 =EC=EC=0D To: C++ Mail List=0D Subject: [Dev-C++] Memory=0D =0D Hi coders,=0D =0D I have a question that does not want to shut up! When i code a program, d= o i=0D have to delete all variables before exiting the main function or does the= =0D operating system cares of free all the memory allocated? If i do not dele= te=0D the variables before main function and use the program several times, may= it=0D cause the system memory to be unavailble?=0D =0D Any input welcome!=0D =0D =0D =3D=3D> When the program terminates, the OS releases all the allocated me= mory, both on the stack & the free store. However, it is a bad habbit to do not free allocated memory on the free store, when you do not need it anymore, because till it terminates you are losing avaiable memory. For example th= ere are programs that run all the time in a loop or something, minimized, dedicated systems etc where you do not close the application.=0D =0D On a garbage collected system (like .NET for example but there are others too), you do not need to free explicitly the allocated memory on the free store, since the GC engine undertakes this task and frees unused memory w= hen it needs more. However even in these systems i prefer to deallocate memor= y explicitly.=0D =0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys=20 |
|
From: Jason H. <jas...@bt...> - 2001-12-05 18:44:14
|
I wouldn't try and count the amount of memory available as you would get a missleading figure. Memory addresses don't directly map to the real addresses used by the system and Windows makes up for lack of physical RAM by using Virtual Memory (a swap file). Also trying to access memory not assigned to you will cause access violations to occur. After a quick look in the Win32API Reference I found the function GlobalMemoryStatus(); which can be used to obtain various memory usage details, including the amount of physical RAM in the system. A quick summary: #include <windows.h> #include <iostream> ... MEMORYSTATUS meminfo; meminfo.dwLength = sizeof(MEMORYSTATUS); GlobalMemoryStatus(&meminfo); cout << "Amount of Physical RAM = " << meminfo.dwTotalPhys << endl; ... This is an untested segment, but should work OK. Check out the Win32API Reference for more information. Jason. ----- Original Message ----- From: "Ian Weston" <lak...@ho...> To: <dev...@li...> Sent: Wednesday, December 05, 2001 5:11 PM Subject: [Dev-C++] Memory > Hello everybody. i was wondering, does anyone know the code that will count > the amount of memory in you PC. > > thanks in advance to anyone that can help. > > > _________________________________________________________________ > Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |