My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative


Reply
 
LinkBack Thread Tools Display Modes
May 27th, 2008, 07:05 AM   #1
 
Joined: Dec 2007
Posts: 37
Memory usage

Hello everybody. I'm making a program for a project of some kind and it's using a lot of memory so I was hoping to find out what function does this. Now, I was thinking of getting the value of used memory before and after the function being executed, but I can't seem to find a function for C++ that gives this value. So, I was hoping if you could help me.
milin is offline  
 

My Computer Forum is free to register and we welcome everyone!

May 27th, 2008, 11:27 AM   #2
 
Joined: Dec 2007
Posts: 232
Re: Memory usage

Frankly I tend to use just the task manager to see how much memory is used -- no need to program anything.

But if it's your function, you should be able to tell how much memory it's allocating, yes?
CRGreathouse is offline  
May 31st, 2008, 10:02 AM   #3
 
Joined: Dec 2007
Posts: 37
Re: Memory usage

I managed to find the code for this. I have this function that is called about a billion times, and it stacked up my memory for a specific reason. I used the code I got to divide the function into parts and then see which part is making the allocation. In the end I found that all of my trouble was caused because I had a pointer that was going upside down a list in a function that was meant to find an element many many times, and instead of

Code:
<structure_name> *pointer_name;
I wrote

Code:
<structure_name> *pointer_name = new <structure_name>;
Anyway, the code to do this is:

Code:
#include <windows.h>

long int GetMemory(void){
    MEMORYSTATUS ms;
    GlobalMemoryStatus(&ms);
	return ms.dwTotalPhys-ms.dwAvailPhys;
}
This returns allocated memory in bytes.
milin is offline  
May 31st, 2008, 05:30 PM   #4
 
Joined: Dec 2007
Posts: 232
Re: Memory usage

Cool, good to know.
CRGreathouse is offline  
Reply

  My Computer Forum > Computer Science Forum > Programming

Tags
memory, usage



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
The excellent free memory card data recovery software. tangyan Computer Science 0 December 31st, 1969 04:00 PM





Copyright © 2019 My Computer Forum Forum. All rights reserved.