Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / How to find out memory usage of an array.

Author
Message
Fatal Berserker
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 3rd Jul 2010 17:58 Edited at: 3rd Jul 2010 18:15
I got some lagg in my game, but a really big array, and i wanted to know if there was a way for me to be able to calculate the amount of memory it was using, and processing it was using up whenever i changed a value.

Thanks in advance.

[edit]
The arrays is used for pathfinding and it stores the previous steps for each tile so then i can calculate the fastest route to the destination, the size of the array is:

struct GridSquare {
Types Type;
int Open;
int DistanceSteps;
int F;
int G;
int H;
int prevX[Amount of tiles on the X coord*Amount of tiles on the Y coord];
int prevY[Amount of tiles on the X coord*Amount of tiles on the Y coord];
bool Moveable;
};
GridSquare GridSquares[Amount of tiles on the X coord][Amount of tiles on the Y coord];

And i know that has to use up a lot of memory, i just want to know how much, or what else i should do instead of arrays.
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 3rd Jul 2010 19:01
Can you use the sizeof() function for RAM usage?
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 3rd Jul 2010 19:22 Edited at: 3rd Jul 2010 19:23
It would be:



My estimations (Assuming Types is an enum):



So it depends on how big your grid size is.

Do you really need prevX and prevY to hold the entire grid? Isn't their point just to hold the previous step? If you aim to keep track of all moves, use a std::vector (include <vector> and set code generation to /MT)

http://cplusplus.com/reference/stl/vector/

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Fatal Berserker
14
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 3rd Jul 2010 19:24 Edited at: 3rd Jun 2011 01:42
Quote: "Can you use the sizeof() function for RAM usage?"

It returns: 52092828, oh dear lol.
If thats in bits then i guess its 13023207 bytes, 13023 KB, 13Mb, 0.013GB?
Heh, does anyone know a good alternative to storing large arrays like paths?

[edit]
Wow, ok, i realised i put in the wrong code (posted before i read Bran flakes91093s post so i didnt see his example) before i had it on:



Changed it to:


(AmountX and Y are the amount of tiles on that coord)

And the size in bytes? is 50070000... ouch, 47.75 MB if i calculated it right.

When i am pathfinding i got to store all possible paths because it swaps between them when its finding the best route, i heard that binary heaps are another good way of storing this, but whats better binary heaps or vectors?
Or even something else?

PS. Types is indeed an enum and the code for it is:



Login to post a reply

Server time is: 2024-07-04 10:49:58
Your offset time is: 2024-07-04 10:49:58