Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Object size in memory  (Read 1984 times)
0 Members and 1 Guest are viewing this topic.
Offline caraiz

Senior Newbie




Java games rock!


« Posted 2003-09-02 22:11:51 »

Im testing how much memory is an object in memory, and i trying the next in wtk1.0.4....

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public class Rectangle
{
}

public class RectangleB
{
    public byte x,y,width,height;
}

public class RectangleI
{
    public int x,y,width,height;
}

public class RectangleL
{
    public long x,y,width,height;
}


The class Rectangle is 12 bytes, the RectangleB and RectangleI is 28 bytes and RectangleL is 44.

I would like optimize memory size using RectangleB instead RectangleI, but its the same size.....
Anybody knows why RectangleB and RectangleI have the same size? its cause emulator or also its at real mobile?

Thanks

Offline larry

Junior Member




.. son of jor-el, kneel before zod ...


« Reply #1 - Posted 2003-09-04 15:37:05 »

What did you use to measure the memory?

Offline caraiz

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-09-04 17:33:48 »

Quote
What did you use to measure the memory?




memory monitor of wtk1.04 and wtk2.0

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #3 - Posted 2003-09-04 18:43:07 »

>Anybody knows why RectangleB and RectangleI have the same size?
>its cause emulator or also its at real mobile?

I could guess it... the entry points in ram aren't byte accurate. Think about it like clusters, wich are usually about 4k... it doesnt matter if you use 1 byte or 4096 bytes it's always one "full" cluster.

I've seen that several times in C programs too... a struct with "fillers" to align the struct.

弾幕 ☆ @mahonnaiseblog
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #4 - Posted 2003-09-04 23:58:55 »

Yep, your hardware is using 32-bit words.  It is (generally) a lot faster to store and retrieve data on word boundaries, so either Java or the underlying implementation is putting the 8-bit bytes into individual 32-bit memory locations.

Ints happen to be 32-bits already, so they fit nicely on word boundaries.

Hellomynameis Charlie Dobbie.
Offline larry

Junior Member




.. son of jor-el, kneel before zod ...


« Reply #5 - Posted 2003-09-05 08:29:18 »

yep, that seems to be the reason.

A simple "hack" to save memory would be to use ints
and treat them as a byte array[2] using byte masks and bit
logic.

Larry
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #6 - Posted 2003-09-05 09:03:51 »

Quote
A simple "hack" to save memory would be to use ints
and treat them as a byte array[2] using byte masks and bit logic.


That's usually not worth the pain. The additional logic, wich is required, eats some bytes too and compression ratio can turn from "awesome" into "not exsistent".

For example... I had a level file like that:
1  
2  
3  
11111111111111111111 10000000000000000001 10000000000000000001 10000000000000000001 10000000000000000001 10000000000000000001 10000000000000000001 10000000000000000001 10000000000000000001
[values ranging from 0-7]
[...]


6300 bytes in size... it compresses down to 638 bytes. The same binary encoded (with 3 or 4 bits) wouldn't be significantly smaller after compression and the overall size (together with the required logic to decode it) will be slightly bigger than before.

Alot of work and it doesnt even save a single byte... also it took even longer to load lol Smiley

弾幕 ☆ @mahonnaiseblog
Offline shareme

Junior Member




Java games rock!


« Reply #7 - Posted 2003-09-05 10:51:58 »

Quote
Im testing how much memory is an object in memory, and i trying the next in wtk1.0.4....

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public class Rectangle
{
}

public class RectangleB
{
    public byte x,y,width,height;
}

public class RectangleI
{
    public int x,y,width,height;
}

public class RectangleL
{
    public long x,y,width,height;
}


The class Rectangle is 12 bytes, the RectangleB and RectangleI is 28 bytes and RectangleL is 44.

I would like optimize memory size using RectangleB instead RectangleI, but its the same size.....
Anybody knows why RectangleB and RectangleI have the same size? its cause emulator or also its at real mobile?

Thanks



It relates to how int, byte and long are defined bitwise in JVMs..

Since you never goign to see long in J2ME why the question?

Offline larry

Junior Member




.. son of jor-el, kneel before zod ...


« Reply #8 - Posted 2003-09-05 11:19:21 »

Quote


That's usually not worth the pain. The additional logic, wich is required, eats some bytes too and compression ratio can turn from "awesome" into "not exsistent".


very worthy point!
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #9 - Posted 2003-09-24 00:00:43 »

Quote
Since you never goign to see long in J2ME why the question?


?

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
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 (24 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (54 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!