Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (604)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Discussions / General Discussions / Re: Simple JNI task on: 2004-01-29 14:42:34
Quote
stdin and stdout can be read from and written to using System.in and System.out so I wouldn't bother trying to do this in native code.


The executable file will be called from an external program, that will communicate with it through stdin/out, so I haven't the option to use System.out/in! To be specific, I'm going to write a UCI (universal chess interface) for my chess engine.

To write to stdout in C++ one uses "cout >> ..." isn't it? To read from it "cin", but when do I know when new data is available? How to convert to a Java string?

For a C++/JNI expert this should be piece of cake to answer. Please post some code. Thanks!



2  Discussions / General Discussions / Simple JNI task on: 2004-01-28 00:40:25
Hi there,

I have to write a native executable, that first starts my java program and then continously transfers it all input recived from stdin and writes output from the Java program to stdout. Can anyone please show me how to do this (platform-independently) with VisualC++ or gcc?

Ideally there would be two methods in the Java code, one for writing a String and one to accept a String. I'm a complete Newbie in C/C++ and JNI. Are there any pitfalls?

Thanks a lot!
3  Game Development / Performance Tuning / Re: Array access pretty slow on: 2004-01-20 22:36:32
Oh, that was a lighning fast reply Shocked

No, unfortunately i can't (or at least it would be very messy) implement the stack with recursion.

Another question: generally what is faster, 2 accesses to arrays with length 64 or 1 access to an array with 4096 length? I suppose this depends on CPU caching... so it's platform dependant... a rule of thumb?

Have a nice day!
4  Game Development / Performance Tuning / Array access pretty slow on: 2004-01-20 21:45:31
Lastly I tried an optimization in a frequently executed piece of code: 3 variables of small size needed to be saved in a sort of "stack array" of fixed size. In the first version each variable was stored and retrieved from an individual array.

After packing all info into one single array with shifting and oring (saving two array acceses), the code was significantly faster! Obviously array access is much more expensive than a few bit-ops...

But how expensive is it really? I would guess it takes at least two condition checks for the bounds and one multiplication to calculate the address. Does anyone know exactly?


5  Game Development / Performance Tuning / Re: Find out how many CPUs a system has on: 2004-01-10 13:48:39
Thanks, that will be optimal. Strange they added this functionality so late...

An other question comes to my mind. What about this new hyperthreading technology of intels P4 (I read of a 25% performance increase): will a multithreaded java application benefit from it? If that's true, I should use the parallel algorithm with two threads even on a single processor system, hmm... how to detect a hyperthreading processor?
6  Game Development / Performance Tuning / Find out how many CPUs a system has on: 2004-01-10 04:27:33
In my application I need to find out how many processors the host system has, in order to start an appropriate numer of threads (in my case numberOfThreads = numberOfCPUs). Is there a standard means of achieving this in Java? If not, can anyone please give me a hint how to do this platform-independantly with JNI... (I never used native code, so please explain this in a fool-proof manner) Thanks a lot!
7  Game Development / Performance Tuning / Unreachable code removal on: 2004-01-08 01:59:36
When a block of code is unreachable at compile time, will the compiler remove it? Example:

final boolean DO_THAT = false;

if (DO_THAT) {
 // code...
}

In my application I'm specially interested in the removal of the condition check, since the condition will always be true or false at compile time.
8  Game Development / Performance Tuning / Re: Finding index of single 1 bit in a long on: 2003-12-11 22:31:18
Thanks a lot for your help. So basically bitIndex2() seems to be the right thing to do - just not in the fastest variant. Originally I hoped that maybe someone would come up with a better algorithm, maybe exploiting some obscure bit fumbling.

Because my work is in the early stages I'll consider switching to C/C++ and later optimize with assembly. Could be quite fun and challenging - maybe I'll toast my CPU  Roll Eyes I wonder how a C++ and then an asm version would compare in terms of cycles.

Can it be true, that Sun 1.2 is faster than the successor VMs? Strange...

Merry Christmas & Happy new Year
NativeOne
9  Game Development / Performance Tuning / Finding index of single 1 bit in a long on: 2003-12-09 14:14:56
Hi everybody. I'm working on a chess program which makes frequent calls to a method, that finds the position of the first (and only) set bit in a long value. So for 1->0, 2->1, 4->2, 8->3, 16->4, ...

The straight-foward code is this:

 public static int bitIndex1(long x) {
   int r = 0;
   while ((x & (1L << r)) == 0)
     r++;
   return r;
 }

The enhanced version takes less time in the average case:

 public static int bitIndex2(long x) {
   int r = 0;
   if ((x & 0xFFFFFFFF00000000L) != 0) r += 32;
   if ((x & 0xFFFF0000FFFF0000L) != 0) r += 16;
   if ((x & 0xFF00FF00FF00FF00L) != 0) r += 8;
   if ((x & 0xF0F0F0F0F0F0F0F0L) != 0) r += 4;
   if ((x & 0xCCCCCCCCCCCCCCCCL) != 0) r += 2;
   if ((x & 0xAAAAAAAAAAAAAAAAL) != 0) r++;
   return r;
 }

Is it possible to do this even faster? On x86 there is a single assembly instruction which does this kind of stuff Sad
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (27 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (96 views)
2014-12-08 04:46:31

JscottyBieshaar (56 views)
2014-12-05 12:39:02

SHC (72 views)
2014-12-03 16:27:13

CopyableCougar4 (74 views)
2014-11-29 21:32:03

toopeicgaming1999 (134 views)
2014-11-26 15:22:04

toopeicgaming1999 (125 views)
2014-11-26 15:20:36

toopeicgaming1999 (35 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!