is there a sizeof function

Monkey Forums/Monkey Programming/is there a sizeof function

retroX(Posted 2015) [#1]
What is the best way to get the size of objects?
I want to know how much a sprite object pool uses for games such as match-3 or snake.
These games need hundreds of sprite objects in a pool and I want to know how much memory is used by different engines to maintain reasonable memory usage for mobile devices.
Is this even possible to do?
How much memory is allowed to be used by games on mobile devices?
If mobile phones or tablets allow plenty of memory for these type of games then I won't even worry about it.
Any help is appreciated.


Gerry Quinn(Posted 2015) [#2]
Graphic memory is more likely to be the bottleneck, I would say. You could probably have more types loaded into memory than you could easily draw all at once.

For sprites, it should be possible to manually count the total area, at 32 bits per pixel.


retroX(Posted 2015) [#3]
I do not know what memory is used for the image of each new sprite object.
I assume it is ram which is copied into graphic memory every time it is rendered.
I looked at the universal object type used in game engines and at least 80 variables are part of each object.
That is not including the extra memory if the object type is a sprite that has an image included.
So an objectVariable.SizeOf() method would be useful for approximating how much memory would be needed in a snake game,
which could have 500 or more sprites moving on the screen.
I do not know the amount of memory allowed per game on the various mobile devices,
but maybe there would not be any problem.
A function which returns the overall memory usage at the moment would be as useful.
For now I am going to make the snake game and see how it runs on a mobile phone when the snake reaches a size of 1000 body parts.


Nobuyuki(Posted 2015) [#4]
per-app heap size limit depends on phone. Use DDMS to poll for resource usage. At the most conservative, try to avoid going over 32mb. Galaxy S3's heapsize is 64mb. My Nexus S only has 24mb allowed per app to allocate.


nullterm(Posted 2015) [#5]
For an 80 variable object, you're looking at approx 320 bytes per (80 x 4 bytes per value, assuming mostly 32-bit int's).
320 bytes per object x 500 objects = 160,000 bytes, again approximately.
This number is entirely how you design your object, and how many you create. In Monkey X, you design your own sprite class so it's up to you.

Image data is probably gonna be heavier. If you load a new Image per sprite, you'll kill your memory.
But if you just refer back to the same shared/global Image or sprite page (with all sprites on the same or fewer image), then it's cheaper.
256 wide x 256 high x 32 bit/pixel = 262,144 bytes
This number is how you design your artwork, not the engine you are using.

There might be someway to add native functionality to do a sizeof in .cpp code on your class, but I have yet to dabble in that so can't speak about how.


ziggy(Posted 2015) [#6]
but remember that you won't be having accurate information of how many memory your app is using unless you track live objects and garbage collection, which would introduce lots of complexity which I don't think is paired with any tangible gain