|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
Quote:
Quote:
Code:
1 #include <stdlib.h>
2
3 int main()
4 {
5 int *array = malloc(10 * sizeof(int));
6 int *ptr = array;
7 int i;
8
9 for(i = 0; i < 10; i++)
10 ptr++;
11
12 return 0;
13 }
Plus explicit pointers make functions like swap (commonly used in bubblesort simple) simpler using C pass by reference. Again not vital, just something that gets abstracted away in a higher level language. |
|
#2
|
|||||
|
|||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
Quote:
|
|
#3
|
|||||
|
|||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
Quote:
Code:
.L2:
cmpl $9, -12(%ebp)
jg .L3
movl -12(%ebp), %eax
sall $2, %eax
addl -4(%ebp), %eax
movl %eax, -8(%ebp)
leal -12(%ebp), %eax
incl (%eax)
jmp .L2
.L3:
Quote:
Code:
.L2:
cmpl $9, -12(%ebp)
jg .L3
leal -8(%ebp), %eax
addl $4, (%eax)
leal -12(%ebp), %eax
incl (%eax)
jmp .L2
.L3:
Quote:
Last edited by The Lucas : 18-05-2009 at 00:00. |
|
#4
|
||||
|
||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
Quote:
Here is swap with references: Code:
public class MyInt {
int data;
public MyInt(int x)
{
this.data = x;
}
public static void swap(MyInt a, MyInt b)
{
a.data ^= b.data;
b.data ^= a.data;
a.data ^= b.data;
}
}
Last edited by Chris27 : 18-05-2009 at 01:09. |
|
#5
|
|||||
|
|||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
You can't dereference (&) and do pointer arithmetic like that in Java.
Quote:
Code:
ptr = 365; Array indexing requires a symbol (base of array) and a type (size of element). When an integer can be cast to a pointer, pointer arithmetic can be done without an array. Quote:
Again, I understand both languages and the reasons why Java doesn't allow explicit pointers (source of bugs, reference counting for garbage collecting, sercurity, etc..). Lets revisit how this whole conversion happened (with me paraphrasing) Billy: Yuck Java. Pointers ftw Jared: What cant you do with Java references? Me: Pointer Arithmetic. Jared: Granted, but you better have a good reason. <Long posts involving example code by Chris, me and Alan> I thought twice before pressing Submit Reply on my first post because I knew it wouldn't be my last on this thread Programming debates are interesting (for me atleast) but time consuming. Maybe I should have just let Billy reply or learned from C++ vs LV threads.Last edited by The Lucas : 18-05-2009 at 12:23. Reason: oops quote fix |
|
#6
|
|||||
|
|||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
Quote:
|
|
#7
|
|||||
|
|||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
More importantly, how much does it matter in our application? What difference will it make? |
|
#8
|
|||||
|
|||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
(I know that's not Brian's argument, but it is a good excuse to post one of my all time favorite programming urban legends) |
|
#9
|
||||||
|
||||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls *****JAVA DISCUSSION***
I split this conversation into 2 threads into a java discussion and an orbit ball one.
|
|
#10
|
|||
|
|||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
An instruction cycle here or there makes zero difference in the face of the larger picture. If you want to have a truly useless argument, just remember that our new processor is pipelined AND has a double dispatch with multiple ALU elements. So while you are all optimizing the instructions, I'll be working on what I want the code to do. As a point of interest, I know someone who wrote his own graphical programming language that compiles to something that is on average twice as fast as C for embedded power and motion control applications. |
|
#11
|
|||
|
|||
|
Re: **FIRST EMAIL**/Java and Orbit Balls *****JAVA DISCUSSION***
Quote:
Quote:
Quote:
The second is that there is most likely a set of libraries that he uses for the down and dirty interfaces. He optimized them to work with his target platform. Speed in Java the last few years has come from:
If you optimize the algorithm you seldom have to bit fiddle to make it faster. |
|
#12
|
||||||||
|
||||||||
|
Re: **FIRST EMAIL**/Java and Orbit Balls
Quote:
Quote:
Alan, to show that pointer arithmetic can be more efficient than array indexing, I used ptr++ (cant use in Java) instead of array indexing in Chris' example loop. The generated assembly showed: Quote:
So basically I am saying (since my first post here) is pointer arithmetic (that can be done in C not Java) can be slightly more efficient in some situations. Nothing major that will make a significant difference in our robot code. Can we agree on that? Quote:
Quote:
Quote:
Quote:
Quote:
![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| **FIRST EMAIL**/Java and Orbit Balls *****Orbit Ball Discussion**** | Pjohn1959 | FIRST E-Mail Blast Archive | 44 | 18-05-2009 20:19 |
| "Java, Sun SPOT and the FIRST Robotics Competition" | pogenwurst | Programming | 54 | 02-05-2009 23:37 |
| Amazing Circuit Build and Simulation Java Applet | Chris_Elston | Electrical | 2 | 26-06-2008 19:36 |
| Eclipse Plugin, Linux, and a Java Loader | shtylman | Programming | 5 | 17-01-2008 14:44 |
| Learn C, C++, and Java with new board game. | Elgin Clock | Programming | 8 | 04-11-2005 13:28 |