18 December 2022, 20:48 | #1 |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
Know how much memory is in use by program?
Is there a way how to know how much memory is currently being used by a program at some points during the execution of a program?
For example: Code:
call_function_1(); print_memory_in_use(); call_function_2(); print_memory_in_use(); call_function_3(); print_memory_in_use(); |
18 December 2022, 21:57 | #2 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,233
|
The short answer is no. The problem is really that "being used by a program" is not well-defined, mostly because AmigaOs has no such concept as "memory used by a program". There is only "memory used".
C programs may use the standard C library for memory allocation via malloc(), and potentially, there is a vendor-specific function to find out how large the heap is. Unfortunately, the C language does not specify such a function, but maybe there is a vendor-specific extension that provides that function. For AmigaOs, there is, as said, no such function since it is not so uncommon that memory allocated by your program is released by some other program, or vice versa, so one cannot really account memory to a particular program. As an approximation, you may call AvailMem() before your program runs, and then while it runs, and compute the difference. However, that is only an approximation as other programs may have allocated and released memory in between, and memory may have been allocated as side effect of your program operation that may be eventually released, though not by your program. Consider, for example, your program prints something on the console. This "something" needs to be put somewhere in case the console window is reprinted or resized, and hence needs to be stored. Thus, just "printing" may allocate memory, and this memory is probably only released after the console window is closed, or cleared. |
18 December 2022, 22:21 | #3 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,178
|
If it's your program, as in you are writing it, you could just declare your own allocation and deallocation wrappers that keeps track of the amount allocated. This only works with memory managed via your wrappers but implemented properly it's not a bad approximation.
|
18 December 2022, 22:58 | #4 | |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
Thought so as I could not find much when searching for a solution.
Quote:
In summary, all looks fine, all is working fine, but trying to make sure there is no memory leak lurking somewhere. Not sure if anyone has any other ideas? Last edited by Sim085; 18 December 2022 at 23:23. |
|
18 December 2022, 23:53 | #5 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,233
|
For memory leak checking, you can try this program:
http://aminet.net/dev/debug/MemLog.lha Note, however, that due to the above complications, it may not be perfectly accurate. There are some usage instructions in the archive. |
19 December 2022, 00:06 | #6 | |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
Quote:
Thank you for this. Will go through it |
|
21 December 2022, 18:57 | #7 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,434
|
Hi Sim085!
I highly recommend using fortify: it very simple to use and it will detect many memory issues (overwrite, underwrite, multiple frees, etc.) *and* it will tell you exactly how much memory was allocated, even the largest allocations, etc. Cheers! |
22 December 2022, 08:51 | #8 | |
Registered User
Join Date: Apr 2009
Location: N/A
Posts: 962
|
Quote:
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
A program that snoops and creates full catalog / cd files from memory | ancalimon | request.Apps | 0 | 13 August 2020 13:28 |
Finding start and end of my program's memory? | Warty | Coders. C/C++ | 8 | 03 January 2019 11:24 |
Tracking a game/program's memory usage | clebin | Coders. General | 5 | 01 December 2017 10:46 |
How to load program into fixed memory area | ShK | Coders. System | 3 | 07 July 2016 09:46 |
Best program to test memory? | Mustangjeff | support.Hardware | 5 | 05 October 2012 07:43 |
|
|