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.




×
×
  • Create New...