Jump to content
  • 0

Having A Lot Of Objects Into An Arraylist.


Question

Posted

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)?

 

 

8 answers to this question

Recommended Posts

  • 0
Posted

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 ?

  • 0
Posted (edited)

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
  • 0
Posted

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

  • 0
Posted

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

  • 0
Posted

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.

  • 0
Posted

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)

  • 0
Posted

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.

Guest
This topic is now closed to further replies.


  • Posts

    • Good day! Due to the increasing number of questions, "Do you provide services for the client?" - I decided to answer with a separate topic. I provide services for editing/modifying the client and individual files, namely: 1. Transfer/Creation/Editing locations, geodata.   2. All kinds of work with NPCs, including transfer, animation, adding effects to them and logos.   3. Actually, Transfer/Creation/Edit any EFFECTS, including Abnormal Effects.   4. Any work with weapons, armor, accessories and everything related to it.   5. Create or edit textures, including dynamic textures.   6. Creating a Lobby Screen, Lobby Char Selection (character selection window) and Lobby Char Creation (character creation window). What I don't do: 1. Coding in any form (except for CB).   I started publishing my work recently, here - YouTube And here - RuTube If required, I respect confidentiality. Any other questions? Welcome to Telegram or PM.
    • 🎮https://discord.gg/yyVRtna9RB 🌎https://l2-forever.com L2 Forever was the best mid rates PvP server back in C4 and C5 and we want to give players the same experience with Interlude!   # L2-Forever * EXP: 50x * Adena: 200x * Spoil: 5x * Drops: 5x   # ENCHANTS *Safe Enchant : 3 *Max. Enchant : 20 *Normal Scroll chance : 65% *Blessed Scroll chance : 70%   # NEW PLAYERS * Start with Coupons allowing you to get free top D-grade * Start at level 20 * Main Town Giran Harbor   # BOOSTED AREA'S * Execution Grounds [ 20 - 40] * Cruma Tower [40-52] * Antharas Lair [52-61] * Antharas Heart [61-80] * Giran Harbor - Shopping Area   # END GAME FARMING AREAS * Monastery of Silence and Primeval Island customized for group farm # PLATINUM ARMORS * Platinum Armors get dropped by raids, allowing everyone to obtain a set and not only donators * Many Raids all over the L2 world drop parts of the Platinum Armors   # BUFFS * Buff duration is set at 1 hour for normal buffs (Buffs and Songs / Dances) * Town Buffers in all main towns with all available buffs Giran Harbor (GH) is the place to be for all your trades and item needs! Platinum Armors   # FOREVER ITEMS * Unique Forever weapons & armors # UNIQUE L2 FOREVER AUGMENTATION SYSTEM * We don't use retail augmentations, we use our own unique system and glows!   # OTHER CUSTOM FEATURES * Global Gatekeeper * NPC Class Changer * Auction House * Unique Augmenter * Subclass with Adena or from Cabrio * Nobless - Barakiel * Useless S weapon Special abilities like (Cheap shot) are changed
    • 🎮https://discord.gg/yyVRtna9RB 🌎https://l2-forever.com L2 Forever was the best mid rates PvP server back in C4 and C5 and we want to give players the same experience with Interlude!   # L2-Forever * EXP: 50x * Adena: 200x * Spoil: 5x * Drops: 5x   # ENCHANTS *Safe Enchant : 3 *Max. Enchant : 20 *Normal Scroll chance : 65% *Blessed Scroll chance : 70%   # NEW PLAYERS * Start with Coupons allowing you to get free top D-grade * Start at level 20 * Main Town Giran Harbor   # BOOSTED AREA'S * Execution Grounds [ 20 - 40] * Cruma Tower [40-52] * Antharas Lair [52-61] * Antharas Heart [61-80] * Giran Harbor - Shopping Area   # END GAME FARMING AREAS * Monastery of Silence and Primeval Island customized for group farm # PLATINUM ARMORS * Platinum Armors get dropped by raids, allowing everyone to obtain a set and not only donators * Many Raids all over the L2 world drop parts of the Platinum Armors   # BUFFS * Buff duration is set at 1 hour for normal buffs (Buffs and Songs / Dances) * Town Buffers in all main towns with all available buffs Giran Harbor (GH) is the place to be for all your trades and item needs! Platinum Armors   # FOREVER ITEMS * Unique Forever weapons & armors # UNIQUE L2 FOREVER AUGMENTATION SYSTEM * We don't use retail augmentations, we use our own unique system and glows!   # OTHER CUSTOM FEATURES * Global Gatekeeper * NPC Class Changer * Auction House * Unique Augmenter * Subclass with Adena or from Cabrio * Nobless - Barakiel * Useless S weapon Special abilities like (Cheap shot) are changed
    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/uthciha-services https://campsite.bio/utchihaamkt
  • Topics

×
×
  • Create New...