How do I Keep my memory useage as low as possible

Get help using Construct 2

Post » Mon Jul 14, 2014 11:26 am

Hi all!

I'm working on a fun game. It's big and advanced..

Now.. i always take a look at the memory usage with every step i do.

Yet i want to create a character "wardrobe" where you can "tune" your character with some fun suits and stuff..

As you can image, every single piece of clothes ( sprite ) i put in my memory limit extends.

Every single suit(sprite) i put in takes up 0.8MB memory limit each..

Is there any way i can keep my Memory Limit low but my sprites high :)!?

Thanks in advance!
B
10
S
4
G
3
Posts: 177
Reputation: 2,541

Post » Mon Jul 14, 2014 11:44 am

Have you tried make one sprite for a type of costume and populating that with images ?

Also how exactly do you test the RAM memory used? Just by looking at the counter on the status bar in Construct 2 at the bottom?
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
38
S
9
G
1
Posts: 174
Reputation: 3,233

Post » Mon Jul 14, 2014 12:01 pm

Hi Je Fawk,

Thanks for your reply.

Yes i am always thinking in the memory save way but non-the-less some things can't be changed.. I have one sprite with all other clothes as animation frames ( complete suits, no lose parts ).

Yet i indeed only look at the counter on the status bar.

I guess this isn't probably precisely what it will be once exported etc..

Yet i want to add more than 20-30 different sprites ( frames ) which takes 0.8 mb each what will result in about 20MB..

I'm just not sure how seriously i should take that memory usage in the bottom status bar..
B
10
S
4
G
3
Posts: 177
Reputation: 2,541

Post » Mon Jul 14, 2014 2:54 pm

I read a lot of optimization info regarding Construct 2, however i could not find anything related to RAM usage, only CPU and GPU.


Your best bet on an Android device would be to use an app. Sadly I cannot post URLs :(

My suggestion is to compare the Construct 2 memory number with those in a test project while using a few scenarios. You might find that the objects not on the screen might not be loaded into the RAM, thus your wardrobe must display as few sprites per page as possible to make it RAM-efficient.

Here's a snippet on how to create a log file with RAM usage in Android:

How to get a heap dump


I created the heap dump using the emulator.
I created a new avd for the 1.5 preview:

Code: Select all
android create avd -n test -t 2
emulator -avd test


Then you can logon to the emulated phone and make sure that the /data/misc directory is writable :

Code: Select all
adb shell
chmod 777 /data/misc
exit

Heap dumps are actually created by sending the process a SIGUSR1 (-10) signal.

Code: Select all
adb shell ps


check for the pid of your application

Code: Select all
adb shell kill -10 pid



You can check with

Code: Select all
adb shell logcat

whether it works. You should see something like:

Code: Select all
I/dalvikvm(  ): threadid=7: reacting to signal 10 I/dalvikvm(  ): SIGUSR1 forcing GC and HPROF dump I/dalvikvm(  ): hprof: dumping VM heap to "/data/misc/heap-dump-tm- pid.hprof-hptemp". I/dalvikvm(  ): hprof: dumping heap strings to "/data/misc/heap-dump-tm124026 3144-pid.hprof". I/dalvikvm(  ): hprof: heap dump completed, temp file removed D/dalvikvm(  ): GC freed 1292 objects / 92440 bytes in 11 sec D/dalvikvm(  ): GC freed 215 objects / 9400 bytes in 963ms


now you can copy the heap dump from the (emulated) phone to the Desktop machine:

Code: Select all
adb pull /data/misc/heap-dump-tm-pid.hprof address.hprof


Now the file you will get does not conform to the "standard" Sun .hprof format but is written in Dalvik's own format and you need to convert it:

Code: Select all
hprof-conv heap-dump-tm-pid.hprof 4mat.hprof


Now you can use the Eclipse Memory analyzer to analyze the memory usage of your application.




Good luck!
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
38
S
9
G
1
Posts: 174
Reputation: 3,233

Post » Mon Jul 14, 2014 3:07 pm

I'm guessing not all wardrobes will be worn at the same time, so there's no need for all of them to be on the layout..
I guess I'd put the wardrobes as seperate sprites on a seperate layout and only create the one needed through events.
Would that work in your situation?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jul 14, 2014 5:05 pm

Hi Yall,

Thanks for the awnsers.
I will take a look into the long story.

As you say, i indeed not taking the whole wardrobe..

So this makes my question more obvious.. Since memory usage going up once i insert a sprite. Even when i'm not placing it in game the memory usage rises.

So this makes my question complete:
"Does memory usage slow down the game EVEN if you don't add all the sprites in-game at once."

I could have a character which can only run left and right, yet with 100 animation frames that are not used. Yet my memory usage will be 100MB.

Does this impact my game itself?

Ofcourse i can try it out but my PC runs it smooth as always, yet i can only test on a Note 2 which is pretty smooth also..
B
10
S
4
G
3
Posts: 177
Reputation: 2,541

Post » Mon Jul 14, 2014 5:15 pm

Use emulators, make a test project with a lot more sprites and try to reach the maximum RAM for the low-end emulated device (which is usually 512MB). Once you reach by whatever means possible the 512 in Construct, export it and emulate it; see how it goes.

You can then extrapolate the results for the higher end devices.
Black Bobby The Hole RPG game Greenlit with 303 votes.
B
38
S
9
G
1
Posts: 174
Reputation: 3,233


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests