Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Getting the memory size out of a class?  (Read 692 times)
0 Members and 1 Guest are viewing this topic.
Offline idFade

Junior Newbie





« Posted 2011-06-15 18:37:48 »

I made a class for a tilemap that I want to get the amount of memory it allocates of.

The class looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
import java.awt.*;

public class Tile {

   protected Image tileImage;
   protected int xposition, yposition;
   
   public Tile(Image tile, int x, int y){
      tileImage = tile;
      xposition = x;
      yposition = y;
   }
   
   public Image getImage(){
      return tileImage;
   }
   
   public int getImageWidth(){
      return tileImage.getWidth(null);
   }
   public int getImageHeight(){
      return tileImage.getHeight(null);
   }
}


How do I do this?

I need to create a very large 2D array so I need to know how much each reference of this class takes up.
Offline cylab

JGO Ninja


Medals: 38



« Reply #1 - Posted 2011-06-15 21:49:45 »

First: you don't need to know the size of anything to make a 2d array in java.

Despite that, the size of the reference would be the size of a memory pointer, so afaik 32 or 64 bit depending on CPU-Architecture and JVM.

The size of your class' instance would be the size of the reference to the image + the size of the two ints. Could be there is some more overhead that the jvm needs for an object instance, but I don't think so. For the overall memory consumption you need to add the reference to the instance and of course the Image itself.

If you want to dive into this, you could take the time and make yourself comfortable with a java profiler (Netbeans contains one and the standalone VisualVM might have the needed features, too), so you can see exactly what memory your game is using.

As for your tiled engine, it might make more sense to store one image with all tiles and only the coordinates of the rects containing the specific part in your Tile. 

Mathias - I Know What [you] Did Last Summer!
Offline idFade

Junior Newbie





« Reply #2 - Posted 2011-06-16 00:15:33 »

Thanks, now that you mention it, using a strip of tiles is indeed much better than having each tile store a reference to an image file, I didn't think of that.

I wanted to know how much memory one reference of the tile would take up since I plan on creating a very large 2D array of tiles, and I don't want to consume all my system memory. If it indeed only takes up enough for the variables and the image reference then it wouldn't be that much ^^
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!