-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt example to discuss about memory usage
- Loading branch information
1 parent
d8d0502
commit 2e23021
Showing
2 changed files
with
58 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* file: memory_usage.h | ||
* >> captures the number of bytes used by malloc | ||
*/ | ||
|
||
// NOTE: LINUS ONLY | ||
|
||
/* system header files */ | ||
# include <math.h> | ||
# include <t8.h> | ||
# include <stdlib.h> | ||
# include <malloc.h> | ||
|
||
static inline | ||
double | ||
memory_usage(int display){ | ||
/* get malloc info structure */ | ||
struct mallinfo my_mallinfo = mallinfo(); | ||
|
||
/*total memory reserved by the system for malloc currently */ | ||
double reserved_mem = (double) my_mallinfo.arena; | ||
|
||
/* get all the memory currently allocated to user by malloc, etc. */ | ||
double used_mem = (double) my_mallinfo.hblkhd | ||
+ (double) my_mallinfo.usmblks | ||
+ (double) my_mallinfo.uordblks; | ||
|
||
/* get memory not currently allocated to user but malloc controls */ | ||
double free_mem = (double) my_mallinfo.fsmblks | ||
+ (double) my_mallinfo.fordblks; | ||
|
||
/* Print out concise malloc info line */ | ||
if (display) { | ||
t8_global_essentialf("MEMORY USAGE: %f MB(%.0f) malloc: %f MB reserved (%.0f unused)\n", | ||
used_mem / (1024.0 * 1024.0), | ||
used_mem, | ||
reserved_mem / (1024.0 * 1024.0), | ||
free_mem); | ||
} | ||
return used_mem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters