Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sponge

[java] Using built-in vector / linked list vs. manual implementation

This topic is 5237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m choosing between using the built in vector/linked list class from java (haven''t decided which) or makeing my own manually (ie an object with a next node) to handle my game objects. My gut feels that doing it manually should be faster, but is doing it manually worth the gain in speed? Especially for 5-15 objects on screen. And what about more objects (50-100)? which would be better then? Also, this is for a project, and doing it manually would impress my teacher more :-) but im lazy so if it''s not worth the trouble im not going to bother. Thanx..

Share this post


Link to post
Share on other sites
Advertisement
I''d suggest using what''s already there. I haven''t worked much with Java, but my guess is that they''ve done what they can to make it quite fast, and more importantly, bug free and standardized. This is certainly the case with C++. You''re unlikely to make it much faster, if at all, unless you know a lot of ways to take shortcuts, because you know about some specific properties of your data.

However, making your own can be good experience. But if you already have, then I would consider it more impressive to use the standard implementations that already exist.

Share this post


Link to post
Share on other sites
I don''t really think that it''ll make anything faster at all if you were to write your own (unless you do TONS of optimizations). After all, they wrote those utilities for a reason: So you don''t have to.

That said, it certainly can''t hurt to write your own that way you get proactice in doing so and you can understand better how they work. But that''s really the only reason I can think of to not use the builtin ones.

http://chaos.webhop.org

Share this post


Link to post
Share on other sites
For 5-10 I doubt it would matter what you use, and even 50-100 is not that taxing.

It would probably impress your teacher more to use the existing containers - unless the assignment is to write your own data structures.

Share this post


Link to post
Share on other sites
Well, you could get a very tiny speed improvement by coding your own data structures that didn''t require the casts to/from Object. But its usually not worth the effort, and for 50 - 100 elements, its definitely not worth the effort.

Use the built in containers

Share this post


Link to post
Share on other sites
Use ArrayList instead of Vector. It is a faster implementation. Unless you need code syncronization, ie multiple threads accessing the same data structure, you shouldn''t use Vector.



First make it work, then make it fast. --Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post


Link to post
Share on other sites
Doing it manually will be faster, for 2 reasons:

-no casting (like NuffSaid said)
-no synchronized methods (you mostly don''t need synchronized methods, but the methods of java.util.vector are synchronized)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I dont know where the conception came from, but object reference casting is not slow. All it has to do is check if the cast target is in the object''s inheritance hierarchy, it''s nothing like casting primitive data types.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How can you possibly think that your own linked list would be faster? Please.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!