Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  memory alocation  (Read 1397 times)
0 Members and 1 Guest are viewing this topic.
Offline Raghar

Junior Duke




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Posted 2004-10-03 13:02:27 »

I have a little question about sizo of objects in the memory.

How big would be a difference between this

class a {
b  some = new b[1000];
class b{
int a;
int ouch;
}
}

and this
class a {
b some = new b[1000];
}
class b{
int a;
int ouch;
}


and how much memory would eat this:

byte[][] by = new byte[1000000][1];

I tried it on JVM 1.5 beta3 and it looked horrible.
basically 4 MB + 15 MB
Offline abies

Senior Duke





« Reply #1 - Posted 2004-10-03 14:16:53 »

In first case, you get 1 extra word for outer class reference. You cannot really compare the memory, as meaning is different. If you put static class b in first case, then it will be the same as second.

byte[][] by = new byte[1000000][1];  is about the worst thing you can do. Array will take at least 16 bytes of memory, maybe even 24 (class pointer, gc/hashcode word, array size, contents, padding to rounded size).  so byte[1][1000000] will take around 1MB, and byte[1000000][1] around 16-24MB.

Artur Biesiadowski
Offline Raghar

Junior Duke




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #2 - Posted 2004-10-05 19:17:13 »

Aw nasty. Isn't it unnecessary to have additional reference for inner class? It did a nasty things with PPM compressor, 200000 nodes is a little amount.

Yes I forgot on the array size, however, it's more like 24 - 30 bytes. I rewrote it into a "pointer arithmetic", and it's working now much better.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #3 - Posted 2004-10-06 01:19:21 »

Quote
Aw nasty. Isn't it unnecessary to have additional reference for inner class?


How will the inner class access the outer object without the reference?

You are aware that in the first case 'b' objects have access to all the instance members of the outer 'a' object right?

http://www.javaranch.com/campfire/StoryInner.jsp

Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #4 - Posted 2004-10-06 01:22:42 »

Quote
I rewrote it into a "pointer arithmetic", and it's working now much better.


Why not just swap where you put your index variables?  Instead of array
  • [y] use array[y]
  • , then the array can be the more optimal [1][1000000] case.

Offline Mithrandir

Senior Duke




Cut from being on the bleeding edge too long


« Reply #5 - Posted 2004-10-06 23:44:32 »

Just wanted to add to swpalmer's great explanation. Just remember that arrays are fully fledged objects in Java. Something declared as int[] can be passed into an argument declared as Object.  That means you get a lot of class overhead for every dimension of the array above the first.

The site for 3D Graphics information http://www.j3d.org/
Aviatrix3D JOGL Scenegraph http://aviatrix3d.j3d.org/
Programming is essentially a markup language surrounding mathematical formulae and thus, should not be patentable.
Offline Raghar

Junior Duke




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #6 - Posted 2004-10-09 15:16:23 »

x  = 1 - 1000000
y = 2 - 1000
y passed into another method as a small arrays.
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!