Jump to content
  • 0

Having A Lot Of Objects Into An Arraylist.


Solomun

Question

Lets say i have an ArrayList list = new arraylist<l2pcInstance>. This list has about 1.000.000 l2pcinstance objects.

 

Do you think this would be a problem?

 

Lets say i want to create a method somewhere like:

 

getPlayersByLocation(String location)

{

     ArrayList beta = new ArrayList<L2PcInstance>();

     for (L2PcInstance pc : list)

      {

           if (pc.getLocation.equals(location)

                  beta.add(pc);

     }

    return beta;

}

 

Do you think this would cause a problem to servers memory? If this arraylist has about 1m items + i search in all of them frequntly?

I mean, it is better to search all time the database (SELECT from players where location = location)?

 

 

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

you will never need direct access of the location of 1KK players, so find another solution for your problem.

 

PS: That code is shit, what the fuck String location stands for ?

 

The question is not about Lineage. The question is general. I just asked it here because i know its kinda alive section.

 

The main question is which is the best way to search for players by location.

 

Is it better to do it from ArrayList players or open database and execute "Select from players where location = loc bla bla"

Edited by Solomun
Link to comment
Share on other sites

  • 0

searching a populated arraylist is always better and faster than running a sql query if you arraylist has the same data as your sql

 

Ok thanks, i apreciate that. However, are you sure about that? :P

Link to comment
Share on other sites

  • 0

Ok thanks, i apreciate that. However, are you sure about that? :P

It's called caching. If your db table data is stored in a List on server startup then this means that you have the same data in a list and in a DB table.

The reason you imported it to the List is to not repeat the heavy process of getting 1m items from the database.

 

Looping around a datatype object is always lighter that getting the same data from the db in a new list.

Link to comment
Share on other sites

  • 0

Ok thanks, i apreciate that. However, are you sure about that? :P

 

yes he is , even reading from database wouldn't be a problem. (NO EFFICIENT OFC , i just mean that java , actually almost all programming languanges in our days can handle a lot more you can imagine)

Link to comment
Share on other sites

  • 0

yes he is , even reading from database wouldn't be a problem. (NO EFFICIENT OFC , i just mean that java , actually almost all programming languanges in our days can handle a lot more you can imagine)

No, if you try to get 1 million results in any language you will experience delay. It is not a light task.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...