Jump to content

[Best Way To Store Temporary Objects On Ram]


Recommended Posts

First of all, those locations are going to be just loaded and stay the same until server or xml restart yes? Then you dont need to make them .shared().

If you dont need shared, why bother to use FastMap at all, it is better to use HashMap.

 

Since you are querying the data by just .get(ID), map will be faster than list or set or other collections. 

You should notice that Map<Integer, something> creates Integer object for each record. Integer is not the same as int, it takes far more memory. If you have small collection, thats fine, why would we care. If you have big collection like all items, thats big deal.

Also in getMapById(int) int is cast to Integer, it takes additional time, but thats fine. You might use .getOrDefault in there, takes just 1 line.

 

ArrayList thing in MapData i skip.

 

Well it was trashcode anyway i wanted show you the style even the shared was for previous use i removed them anyway.

 

Btw is there any way to contact you via skype or something i want show you the code in private, cause many kids like Napster321ॐ who buy apple computers. 

It ended up 150 lines it's basicaly 3 HMs and 2 Ssets. 

 

Mostly i care for the design pattern, ill pay attention on how fast it is afterwards.

Thanks for attention.

Link to comment
Share on other sites

Gosling would commit suicide if for some reason see this section... :lol:

Why ? It's suggestion for a stucture, mostly like advice e.t.c Why someone would have a problem when someone asking an advice. 

I suicide everyday watching kids beggin for premade codes lel 

Link to comment
Share on other sites

What's your problem with FastList ? It's not because you write SuperFastList then it will be faster than FastList. FastList is similar to a LinkedList, it is way slower/fatter than a ArrayList. Same for Maps.

 

Stop to use that container, ffs.

 

---

 

As I said, you misconcept Java structure. Try to analyze an existing "holding object" and "table". I named few of them, but basically the whole datatables package is full of those. According to you why on L2J you haven't .get.get.get scenarios ? Think a little about it. That's not because you code complex things and L2J doesn't. It simply because you take the wrong path doing it.

 

Write and define each class informations before trying to develop. You just waste your time coding crap actually.

 

Finally a .get() will return null if not found. So you can simply write following without any trouble :

public MapData getMapById(int id)
{
    return _map.get(id);
}

I invite you to read my previous answer over and over until you get it, because I doubt you will find a better explanation.

Edited by Tryskell
Link to comment
Share on other sites

First of all, those locations are going to be just loaded and stay the same until server or xml restart yes? Then you dont need to make them .shared().

If you dont need shared, why bother to use FastMap at all, it is better to use HashMap.

 

Since you are querying the data by just .get(ID), map will be faster than list or set or other collections. 

You should notice that Map<Integer, something> creates Integer object for each record. Integer is not the same as int, it takes far more memory. If you have small collection, thats fine, why would we care. If you have big collection like all items, thats big deal.

Also in getMapById(int) int is cast to Integer, it takes additional time, but thats fine. You might use .getOrDefault in there, takes just 1 line.

 

ArrayList thing in MapData i skip.

 

Sorry but 99% of java primitives are fake primitives and/or are wrapped every time into Integer objects in java internally in most cases. Yeah also java has so much more features that die right after the compilation and developers never know until they learn to read bytecode. Java doesn't run on the metal and even "when" it does throught the the JIT you still have the memory overhead of the objects, everything is an object until its interpreted by the VM, and most likely even "primitives"

 

PS: int.class

Edited by xxdem
Link to comment
Share on other sites

Why ? It's suggestion for a stucture, mostly like advice e.t.c Why someone would have a problem when someone asking an advice. 

I suicide everyday watching kids beggin for premade codes lel

 

I suggest you to read some book about algorithms and data structures. You will see that there is no magic in HashMap, FastMap, etc, etc. :lol:
Link to comment
Share on other sites

Sorry but 99% of java primitives are fake primitives and/or are wrapped every time into Integer objects in java internally in most cases.

 

PS: int.class

Do you mean that in 99% of cases Integer is made instead of int? In what cases actually?

Link to comment
Share on other sites

Do you mean that in 99% of cases Integer is made instead of int? In what cases actually?

 

That would be true, Trove library would have no purpose to exist, at least for container such as List and Map. And there would have no performance boost, either in RAM or CPU (and the RAM one was currently existing).

 

I doubt Java 8 edited anything prior to that, so you can assume he says wrong things. Fix me if I'm wrong.

Edited by Tryskell
Link to comment
Share on other sites

What's your problem with FastList ? It's not because you write SuperFastList then it will be faster than FastList. FastList is similar to a LinkedList, it is way slower/fatter than a ArrayList. Same for Maps.

 

Stop to use that container, ffs.

 

---

 

As I said, you misconcept Java structure. Try to analyze an existing "holding object" and "table". I named few of them, but basically the whole datatables package is full of those. According to you why on L2J you haven't .get.get.get scenarios ? Think a little about it. That's not because you code complex things and L2J doesn't. It simply because you take the wrong path doing it.

 

Write and define each class informations before trying to develop. You just waste your time coding crap actually.

 

Finally a .get() will return null if not found. So you can simply write following without any trouble :

public MapData getMapById(int id)
{
    return _map.get(id);
}

I invite you to read my previous answer over and over until you get it, because I doubt you will find a better explanation.

 

I did read every answer you did, i'm taking ideas i did what you said but it need some work when it come in such a structure program to avoid mistakes.

One of the problems i face is when u load the values from xml to pass them on the structure it's kinda confusing 

 

everytime xml load lets say "Map"

it take the Map ID and the next value the Map Name so afterwards idk what exactly should i do, make directly a hashmap and bla bla thats where i stuck and i work on.

Sound kinda funny but i'm sure all had problems like this :P but at least it worked until now by 75% since last time that i made it with HM into HM into HM -.-  oh god.. trashcode ftw.

 

Also dafaq with this HashMap it replace the key if its the same, it need also an index.. cause if i make a template (statset Map) for event 1 and then another one (Statset Map) for event 1

the new one will replace the old.. 

 

 

What the data you want to FAST store? Post here all properties.

 

There is no specific data i want store, take example Nexus Engine. 

It store all maps and it's locations in sql as:

 

Map: Giran Castle town

Locations: team1,5921,512-295;team2,952,5982-1295; 

Rewards: winner,57,10000;

e.t.c

 

Basically it make everytime a connection as i saw from the jar. I don't want this, i want avoid connections and raw maps as i mentionted before  map into map into map and i want extend this by using Stats set

 

Now as tryskell said i did some mistakes for ex using Javolution which is slower but it can be replaced afterwards unless i want trim list which i should use arraylist from the begin. 

But generally the structure would be like this:

 

Event ID (int) -> HashMap <Integer, Statssets>

     * Map ID (int) -> HashMap <Integer, Statsets>

     * Map Name (String)

                * Owner Name (String) -> HashMap <String, ArrayList<int[]>>

                * Location (int[])

      * Colors <HashMap <Integer, HashMap<String, int>>

                * Owner name (String)

                * Owner color (int)

 

This is a structure for example i try to follow, basicaly you call the owner by his name example   int[] loc = Data.getEvent(1).getMap(2).getPosition("RedTeam");

which can be really easy to used. 

 

The problem is that i'm not really familiar with such a structure. The code i posted yesterday as i said its trashcode i made a new one which it works and it has the proper checks 

and afcourse as tryskell said sometimes it return null cause lets be honest.. if you're data does not contain team 3 and u call 3 team then what u expect from the engine to do? Generate a team?

Afcourse you have to becareful a bit. As i said i did a code which it works and i tested it (replaced or FL with AL) and i removed it and redesign it again  but i always come up with some problems in the design pattern.

I don't have problem in coding, coding is so easy, the problem is in the design  as tryskell said again "before you start to code".

 

The reason i made this topic is for people to give some suggestion so i can take ideas and get into faster. I don't want anyone post codes i just wanted skilled people to give some advice on such a structure code

and how it can be done to make your life easier when you load the XML.

 

Already got ideas tho 

 

I suggest you to read some book about algorithms and data structures. You will see that there is no magic in HashMap, FastMap, etc, etc. :lol:

 

Yeap i know i miss this but for now i'm doing this as practice to get over with.

 

Ps. i know there is no magic in HashMap and FastMap but when you need to store some value along with a key... 

Edited by AccessDenied
Link to comment
Share on other sites

That would be true, Trove library would have no purpose to exist, at least for container such as List and Map. And there would have no performance boost, either in RAM or CPU (and the RAM one was currently existing).

 

I doubt Java 8 edited anything prior to that, so you can assume he says wrong things. Fix me if I'm wrong.

Ah, so you are talking about List<Integer>. I am talking about class X{ int y;}

Btw, why didnt you add Trove but made IntIntHolder on your own?

Link to comment
Share on other sites

Tryskell thats for you: 

 

Please don't be super bad and ignore FastMap i'll replace it  it's temporary.

private final Map<Integer, Data> _eventData = new FastMap<Integer, Data>();	
	private final Map<Integer, MapData> maps = new FastMap<Integer, MapData>();
	
	private class Data
	{
		private Map<Integer, MapData> _map = new FastMap<Integer, MapData>();
		
		private Data(Map<Integer, MapData> map)
		{
			_map = map;
		}
		
		public MapData getMapById(int id)
		{
			return maps.get(id);
		}
	}
	
	private class MapData
	{
		private String _mapName;
		private FastMap<String, int[]> _Locations;
		
		private MapData(String mapName, FastMap<String, int[]> locations)
		{
			_mapName = mapName;
			_Locations = locations;
		}
		
		public int[] getMapLocationByOwner(String owner)
		{
			int[] loc = null;
			
			if (_Locations.containsKey(owner))
				loc = _Locations.get(owner);
			else
				System.out.print("Error: Can't find location for owner");
		
			return loc;
		}
		
		public String getMapName()
		{
			return _mapName;
		}
	}
	

	/**
	 * @param String mapName
	 * @param Array ArrayList<int[]>
	 */
	public void addNewMap(int eventId, int mapid,  String mapName, FastMap<String, int[]> array)
	{
		MapData mapData = new MapData(mapName, array);
		Map<Integer, MapData> map = new FastMap<Integer,MapData>(); map.put(mapid, mapData);
		Data data = new Data(map);
		_eventData.put(eventId, data);
	}
	
	/**
	 * 
	 * @param id ~> Event ID
	 * @return Return Map Data base on Event ID
	 */
	public Data getMapByEventId(int id)
	{
		if (_eventData.containsKey(id))
			return	_eventData.get(1);
		else
			System.out.print("Error: Map not found for event ID: " + id);
		
		return null;			
	}

Any suggestions are welcomed. 

 

PS. FastMap will be replaced by ArrayList since is slow

Edited by AccessDenied
Link to comment
Share on other sites

1. Use Event as container with properties. You get one HashMap<Integer, Event>

2. Use Map as container EventMap with properties. You get variable _maps as HashMap<Integer, EventMap> or List<EventMap>

 

Eventually, you get the fast readable data like this:

 

1. Map name - Event.getMap().getName();

2. Spawn location - Event.getMap().getSpawnTeam1();

2. Event colors - Event.getTeam(_teamId).getOwnerColor();

 

StatSet perfect only for big data. Your event system don't be use 100500 event's templates. Therefore, you should use the containers with intuitive methods. Yes, it has more code, but you get less mistakes while writting a code.

Link to comment
Share on other sites

 

Map: Giran Castle town

Locations: team1,5921,512-295;team2,952,5982-1295; 

Rewards: winner,57,10000;

e.t.c

 

Event ID (int) -> HashMap <Integer, Statssets>

     * Map ID (int) -> HashMap <Integer, Statsets>

     * Map Name (String)

                * Owner Name (String) -> HashMap <String, ArrayList<int[]>>

                * Location (int[])

      * Colors <HashMap <Integer, HashMap<String, int>>

                * Owner name (String)

                * Owner color (int)

 

This is a structure for example i try to follow, basicaly you call the owner by his name example   int[] loc = Data.getEvent(1).getMap(2).getPosition("RedTeam");

	public class EventMap
	{
		private final int id;
		private final String name;
		private List<TeamDetails> teams;
		
		public static class TeamDetails
		{
			private final EventTeam team;
			private final Location[] locations;
			private final int color
		}
	}

EventMap map = Rnd.get(eventStructure.getMaps());

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




  • Posts

    • 2 Factor Authentication Code for 100% secure login. Account provided with full information (email, password, dob, gender, etc).
    • ready server for sale, also available for testing with ready and beautiful npc zone pvp with custom 2 epic core orfen lvl2 with all maps ready all quests work at 100% ready comm  board with buffer teleport gm shop service anyone interested send me a pm many more that I forget  Exp/Sp : x30 (Premium: x40)    Adena : x7 (Premium: x10)   Drop : x7 (Premium: 10)   Spoil : x7 (Premium: 10)   Seal Stones : x7 (Premium: 10)   Raid Boss EXP/SP : x10   Raid Boss Drop : x3 (Premium: x5)   Epic Boss Drop : x1 Enchants   Safe Enchant : +3   Max Enchant : +16   Normal Scroll of Enchant Chance : 55%   Blessed Scroll of Enchant Chance : 60% Game Features   GMShop (Max. B-Grade)   Mana Potions (1000 MP, 10 sec Cooldown)   NPC Buffer (Include all buffs, 2h duration)   Auto-learn skills (Except Divine Inspiration)   Global Gatekeeper   Skill Escape: 15 seconds or /unstuck   1st Class Transfer (Free)   2nd Class Transfer (Free)   3rd Class Transfer (700 halisha mark)   Subclass (Items required from Cabrio / Hallate / Kernon / Golkonda + Top B Weapon + 984 Cry B)   Subclass 5 Subclasses + Main (Previous subclasses to level 75 to add new one)   Noblesse (Full Retail Quest)   Buff Slots: 24 (28 with Divine Inspiration LVL 4)   Skill Sweeper Festival added (Scavenger level 36)   Skill Block Buff added   Maximum delevel to keep Skills: 10 Levels   Shift + Click to see Droplist   Global Shout & Trade Chat   Retail Geodata and Pathnodes   Seven Signs Retail   Merchant and Blacksmith of Mammon at towns   Dimensional Rift (Min. 3 people in party to enter - Instance)   Tyrannosaurus drop Top LS with fixed 50% chance   Fast Augmentation System (Using Life Stones from Inventory)   Chance of getting skills (Normal 1%, Mid 3%, High 5%, Top 10%)   Wedding System with 30 seconds teleport to husband/wife Olympiad & Siege   Olympiad circle 14 days. (Maximum Enchant +6)   Olympiads time 18:00 - 00:00 (GMT +3)   Non-class 5 minimum participants to begin   Class based disabled   Siege every week.   To gain the reward you need to keep the Castle 2 times. Clans, Alliances & Limits   Max Clients/PC: 2   Max Clan Members: 36   Alliances allowed (Max 1 Clans)   24H Clan Penalties   Alliance penalty reset at daily restart (3-5 AM)   To bid for a Clan Hall required Clan Level 6 Quests x3   Alliance with the Ketra Orcs   Alliance with the Varka Silenos   War with Ketra Orcs   War with the Varka Silenos   The Finest Food   A Powerful Primeval Creature   Legacy of Insolence   Exploration of Giants Cave Part 1   Exploration of Giants Cave Part 2   Seekers of the Holy Grail   Guardians of the Holy Grail   Hunt of the Golden Ram Mercenary Force   The Zero Hour   Delicious Top Choice Meat   Heart in Search of Power   Rise and Fall of the Elroki Tribe   Yoke of the Past     Renegade Boss (Monday to Friday 20:00)   All Raid Boss 18+1 hours random respawn   Core (Jewel +1 STR +1 DEX) Monday, Wednesday and Friday 20:00 - 21:00 (Maximum level allowed to enter Cruma Tower: 80)   Orfen (Jewel +1 INT +1 WIT) Monday to Friday, 20:00 - 21:00 (Maximum level allowed to enter Sea of Spores: 80)   Ant Queen Monday and Friday 21:00 - 22:00 (Maximum level allowed to enter Ant Nest: 80)   Zaken Monday,Wednesday,Friday 22:00 - 23:00 (Maximum level allowed to enter Devil's Isle: 80)   Frintezza Tuesday, Thursday and Sunday 22:00 – 23:00 (Need CC of 4 party and 7 people in each party min to join the lair, max is 8 party of 9 people each)   Baium (lvl80) Saturday 22:00 – 23:00   Antharas Every 2 Saturdays 22:00 - 23:00 Every 2 Sundays (alternating with Valakas) 22:00 – 23:00   Valakas Every 2 Saturdays 22:00 - 23:00 Every 2 Sundays (alternating with Antharas) 22:00 – 23:00   Subclass Raids (Cabrio, Kernon, Hallate, Golkonda) 18hours + 1 random   Noblesse Raid (Barakiel) 6 hours + 15min random   Varka’s Hero Shadith 8 hours + 30 mins random (4th lvl of alliance with Ketra)   Ketra’s Hero Hekaton 8 hours + 30 mins random (4th lvl of alliance with Varka)   Varka’s Commander Mos 8 hours + 30 mins random (5th lvl of alliance with Ketra)   Ketra’s Commander Tayr 8 hours + 30 mins random (5th lvl of alliance with Varka)
    • Have a great day! Unfortunately, we can not give you the codes at the moment, but they will be distributed as soon as trial is back online, thanks for understanding! Other users also can reply there for codes, we will send them out some time after.
    • Ok mates i would like to play a pridestyle server (interluide, gracie w/ever) Is there any such server online and worth playing?
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock