Help to convert small java code into C++

Help to convert small java code into C++

Page 1 of 1

1 Replies - 3896 Views - Last Post: 25 April 2008 - 08:32 PM Rate Topic: -----

#1 rashi.uh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 25-April 08

Help to convert small java code into C++

Posted 25 April 2008 - 08:28 PM

import java.util.Date;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

// Main Class
public class Main {
static int length = 0x1F400000; // 500 Mb
static long [] a;
static long [] a1;
static int i = 0;
static int k = 1;
static int j;
static int i1 = 0;
static int k1 = 1;
static int j1;
static int x =0;
static int x1 =0;
static long sum = 0;
static long sum1 = 0;
static int slotLength = 0xA00000; // 10 Mb
public static void main(String[] args) throws Exception {
long [] a = new long [50]; // Store the time after each 10 MB write
long [] a1 = new long [50]; // Store the time after each 10 MB read
MappedByteBuffer out = new RandomAccessFile("c:\\test.dat", "rw") // change
.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length); // To Generate a File named as test.dat
while (i < length) {
long beforeCompute = System.currentTimeMillis()+x; // change
for (int j = i; j < slotLength * k; j++)
{
out.put((byte) 'x'); // writes data 'x' in bytes  // change
}
k++;
i = i + slotLength;
long computation = System.currentTimeMillis(); // change
beforeCompute = computation - beforeCompute;
a[x] = beforeCompute;
 x++;
}
for (int m=0; m<x; m++)
{
sum = sum + a[m];
System.out.println(+ sum); // Print the sum by taking it from Array, where the Write time are stored.
}
System.out.println("Finished writing");
long start1 = System.currentTimeMillis(); // change
MappedByteBuffer in = new RandomAccessFile("c:\\test.dat", "rw")  // change
.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, length); // To read from the File named as test.dat
while (i1 < length) {
long beforeCompute1 = System.currentTimeMillis()+ x1;
for (int j1 = i1; j1 < slotLength * k1; j1++)
{
in.put((byte) 'x'); // reads data 'x' in bytes // change
}
k1++;
i1 = i1 + slotLength;
long computation = System.currentTimeMillis();
beforeCompute1 = computation - beforeCompute1;
a1[x1] = beforeCompute1;
x1++;
}
for (int m1=0; m1<x1; m1++)
{
sum1 = sum1 + a1[m1];
System.out.println( + sum1); // Print the sum by taking it from Array, where the Read time are stored.
}
long totalReadTime = System.currentTimeMillis()- start1; // change
System.out.println("Finished reading");
}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Help to convert small java code into C++

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Help to convert small java code into C++

Posted 25 April 2008 - 08:32 PM

You said Help to convert small java code into C++, but all you did was post the Java code, you showed no attempt at solving this on your own. I'm thinking the name of the thread should have been Can you convert this to C++ for me.

Also, please use code tags when posting code, they are used like :code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1