Results 1 to 5 of 5
Thread: Fast array for insertion/removal
- 02-20-2011, 03:21 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 67
- Rep Power
- 0
Fast array for insertion/removal
In Java is there any existing class that stores 10-1000+ values, has fast insertion and removal of values without allocating, is preferably growable, and is contiguous in memory? If not is there anything close?
Just trying to find out if I need to roll my own like I have in C++ or if Java already provides something that would be suitable.
- 02-20-2011, 03:48 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
In Java is there any existing class that stores 10-1000+ values, has fast insertion and removal of values without allocating, is preferably growable
Look at the classes implementing java.util.List
and is contiguous in memory?
Better yet, don't. This isn't doable in Java. The langauge and its many API have no constructs referring to this "memory" of which you speak.
- 02-20-2011, 01:12 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 67
- Rep Power
- 0
Cool I'll check out the java.util.List classes, even if there's nothing useful now it's good to know what's available for later :).
*sigh*, more and more it's becoming obvious that Java just isn't suited for real time or time critical applications, JIT compilers are great but the language still prevents it from being comparable in both speed and efficiency to C++ code, which is a real pain when you are programming for platforms with limited CPU and RAM specs like phones.
I should probably just forget about Java and switch to C++ with the Android NDK for the 100-1000 times speed increases I can get, and the extra RAM I'll have access to (that ironically I wouldn't need in C++), but I wouldn't learn anything if I just take the easy way out ;).
Thanks for the help though :)
- 02-20-2011, 01:46 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
A 100 - 1000 times speed increase? What JVM are you trying to run your classes on? Avery half self respecting JVM does at least some form of JIT compilation and the result is raw machine code. If you really have to, create an ArrayList with a capacity large enough that no reallocations will be necessary. A bit of tuning can help big times.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-20-2011, 03:23 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 67
- Rep Power
- 0
I'm running it on the Android JVM which I believe is Dalvik, before Android version 2.2 it didn't have a JIT compiler so on the older versions the hit is really bad. It's not really Java in general that would give the speed increases though, just some bloated classes that I need to use in Java that are by far my largest bottleneck and one of them has a bug that makes things even slower. Using native code you can just use a memcpy instead of doing a heap of redundant stuff and iterating over large amounts of primitives like these classes do. Here's a link to the specific problem in case you are interested: http://www.badlogicgames.com/wiki/in...er.put_is_slow
The other thing that would net me some further speed increases by going to C++ is that on Android apps are limited to only 16mb or 24mb of heap memory in Java, which means if I go to C++ I won't have those memory restrictions and can use the extra memory to store precomputed data rather than recalculating it one or in some cases many times each frame. I also wouldn't have garbage collection at run time, and with the generally faster code that comes from C++ anyway it can really add up.
But yer, more to do with Java on Android than Java it's self so no need to worry :).Last edited by Skiller; 02-20-2011 at 03:25 PM.
Similar Threads
-
Help me with this array element insertion
By javanew in forum New To JavaReplies: 4Last Post: 09-07-2010, 02:49 PM -
Complete Java Removal
By jpChris in forum New To JavaReplies: 14Last Post: 05-25-2010, 12:46 PM -
Adhoc selection & removal of JLabels
By dan0 in forum AWT / SwingReplies: 5Last Post: 03-10-2009, 06:31 PM -
JAVA: String char removal with nested loop
By igniteflow in forum New To JavaReplies: 3Last Post: 11-28-2008, 02:09 AM -
Removal of Homework Requests
By CaptainMorgan in forum Suggestions & FeedbackReplies: 14Last Post: 08-03-2008, 09:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks