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  
  Stupid books says this but stupid me says that...  (Read 1780 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Duke




Java games rock!


« Posted 2004-01-19 12:14:29 »

The book (Java in 2 semesters, which I need for my course) is saying that there should be no need to use anything below int(Byte) and anything below Double(Float).

I believe that using 'Byte' and 'Float' where it can be used will give out a performance benefit over just using double/int everywhere.

So who is right?

There should be benefits AFAICS.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Online princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-01-19 12:59:27 »

It's not correct, there are times and places to use everything. What you need to understand is why and when, and a book making a blanket statement like that won't help you.

Cas Smiley

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #2 - Posted 2004-01-19 13:12:13 »

Quote
The book (Java in 2 semesters, which I need for my course) is saying that there should be no need to use anything below int(Byte) and anything below Double(Float).


(assuming you meant to use all lower case, and are talking about the primitives only: )

It's probably referring to the fact that the bytecode encodes both versions using the same number of bits; so a java byte, char, and short ALL take the same amount of memory as an int. long and double use twice as much as int and float. Everything else uses the same as int (including boolean, IIRC?)

Cas, what situations are there (other than JIT/Hotspot, JNI comms, and IO, perhaps?) where there's a difference under-the-cover?

NB java bytecode does *preserve* the difference (different bytecodes for whether the 32-bit number is an int or a short), so  Hotspot/JIT/etc could take advantage of this when compiling to native code. I'm not defending the book's statement, just trying to explain it. It may have been true if the book were written long enough ago to predate advanced VM's, but was always a dumb thing to put in a *book*, which tends to hand around a long time!

malloc will be first against the wall when the revolution comes...
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-01-19 13:51:29 »

Quote
It's probably referring to the fact that the bytecode encodes both versions using the same number of bits; so a java byte, char, and short ALL take the same amount of memory as an int.


Huh?  Surely this isn't really the case.  Specially for arrays of primitives.  I mean maybe when they are pushed on the stack they are all pushed as multiples of the machine word size, but as they exist inside Objects I expect the sizes are respected in terms of allocated space, baring any alignment optimizations.

Offline Mark Thornton

Senior Duke





« Reply #4 - Posted 2004-01-19 14:08:43 »

Quote

baring any alignment optimizations.

Java should have less of this than C/C++ as it doesn't have to respect the order of field declarations. So we can order our fields in a logical manner and not distort our source code merely to ensure nice packing.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #5 - Posted 2004-01-19 15:22:20 »

Quote


Huh?  Surely this isn't really the case.  Specially for arrays of primitives.  I mean maybe when they are pushed on the stack they are all pushed as multiples of the machine word size, but as they exist inside Objects I expect the sizes are respected in terms of allocated space, baring any alignment optimizations.


I was only referring to basic bytecode/stack manipulation (I never played with objects-in-bytecode), and I can't remember any further details Smiley. This is what I remember from when I played around with bytecodes years ago...as I said, just trying to "invent" an explanation for what the book was claiming Wink.

malloc will be first against the wall when the revolution comes...
Offline Raghar

Junior Duke




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


« Reply #6 - Posted 2004-01-19 16:47:14 »

It's true that memory is cheap, 4 GB is too small. I recently tried to install windoze on system with 4 MB. and it wasn't mobile phone.
Java in two semesters? How is it different from Java in two weeks, that is avilable somewhere in the Internet?
Teachers are hendayo.
There are few things that could help you in the test.



Java_g_adtest proc something:dword, somethingelse:dword, SomeInt:DWORD, SomeByte1:BYTE, SomeByte2:BYTE
     xor ebx,ebx
     mov eax,SomeInt
     mov bl,SomeByte
     add eax,ebx
     mov bl,SomeByte2
     add eax,ebx

this is JNI

Hey great success, I managed to call ASM without proxy library.

And this would check how much is necessary to store one byte. That's it, after you write that few other lines of code that are necessary to test it.

class ByteObje1{
byte byte1=0;
}

class ByteObje2{
byte byte1=0;
byte byte2=0;
}
Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2004-01-20 22:16:30 »

It used to be that int and long were both stored in a long, for convenience reasons, in Hotspot.  NO general book on Java should be stating this though because its a VM specific thing.

I believe bytes were really bytes, but im not 100% sure.  This is also old information (as of when I did the performance book) and may have changed...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline K.I.L.E.R

Senior Duke




Java games rock!


« Reply #8 - Posted 2004-01-21 22:24:51 »

Jeff, the book said it was for convenience reasons. It didn't mention anything about hotspots.

So in general I should use Byte over int when I can to reduce memory footprint. The book does mention that long/double take up more space in memory over int/float.

Funny book eh? It asks the reader to do the wrong thing(use int/double over byte/float) for convenience but it ends up mentioning that you are going to consume more memory by doing so.

Sometimes I wander what point the book is trying to make? Huh

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2004-01-23 07:19:22 »

The author may not have known himself what he was trying to say... it happens :/

I'd say this:  Use the most appropriate data-type to the kind of data youa re storing and then the VM will do the best it can with it.

This is a specific on a more general performacne tip. Don't look for ways to "trick" the VM.  People who do this end up just hurting themselves 99 times out of 10.  (Yes that was on purpose.)

Give the VM the best information you can about what you are trying to accomplish and then let it do its job.



Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
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 (42 views)
2014-10-16 15:22:06

Norakomi (32 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 (66 views)
2014-10-14 00:35:47

TehJavaDev (59 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 (85 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!