Creating a highscore screen with persistent data in BlackBerry - blackberry

I'm trying to create a highscore screen with 5 strings. I only want to update the screen 1 string at a time, as I create a new high score. If there is no new or old high score I just use the initialized default of 10.
I have been able to use the BlackBerry api and figure out how to create 1 highscore that works completely. However, I'm absolutely stuck on how to create all 5 and sort them within the persistent mechanics. I don't want to post my code because at this point it is such a mess it would be useless.
For reference I am trying to use a string[] and not a vector.

Take a look at this example: http://supportforums.blackberry.com/rim/attachments/rim/java_dev#tkb/14/1/Storing_Persistent_Data_V2.pdf
It demonstrates how you can store different strings in Vector with reference.

Related

How does Firebase choose what to store in its cache with isPersistenceEnabled = true in iOS

I have an app that is using Firebase quite extensively to store data that contains relationships. I want to make sure I am using Firebase as safely as possible in offline mode. The safety concern I have can be demonstrated in the following example:
Assume I have a Zoo model where each individual zoo is stored in Firebase as a subnode of "/zoos".
I have an Animal model where each individual animal is stored in Firebase as a subnode of "/animals".
A Zoo can have Animals which are stored in an ordered list. Specifically, the Zoo model contains an Animal array e.g. [Animal]. This list of Animals is stored in Firebase as a set of position-reference pairs at "/zoos/myZoo/animals" which will contain nodes like:
{0: "animals/fidoTheDog"},
{1: "animals/jillTheCat"}
When I add a new Animal to a Zoo, I need to know how many animals are currently in that zoo so I can add the new animal in the right position like:
{2: "animals/jakeTheSnake"}
If I am offline and happen to read the location "zoos/myZoo/animals" to get the list of animals so I can add in the right position, I want to make sure I have accurate data. I know that if someone else wrote to that position while I am offline and added another animal in position 2, I will get stale data and when I add an animal in position 2, I will overwrite his entry at "zoos/myZoo/animals/2" when I again go online. So that is an issue.
But, if I know I will be the only one writing to that location, can I be relatively sure that Firebase will hold the crucial data at "zoos/myZoo/animals" for me since I am using isPersistenceEnabled = true? In other words, will Firebase just keep that data in cache as long as I have recently written to that location or recently read from that location?
Or do I explicitly need to specify "keepSynced(true)" on that location? This gets to the core general version of the question - How does Firebase choose what to store in its cache with isPersistenceEnabled = true? Especially if I have not specifically set keepSynced(true) on any particular locations. Will Firebase just prioritize recently read data and then when the 10mb limit is hit, discard the old stuff first? Does it matter if I wrote the data to that location a long time ago but consistently read from that location? Will it still maintain that location in the cache because it was recently read? Will it ever discard data before hitting the 10mb limit?
I'm a little bit of a newbie so thank you for your patience with me!
-------------- FOLLOW UP QUESTIONS --------------
A couple follow up questions.
I think the approach suggested in the blog (given by Frank in comments) of using childByAutoID sounds good. So if I am saving a zoo with many animals (in order) then it sounds like I would loop through the animals and use childByAutoID to create a new key for each animal whose value will be the reference to the location of the animal object. Can I be sure that the keys that I create in rapid succession (looping will probably be very fast) will ultimately sort correctly when ordered lexicographically? I’m looking at this blog post and assuming that is the case. https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
Suppose I am doing something more complicated like inserting an animal at the beginning of the list in position zero. Then before doing the operation, I would sync down the list of animals in the zoo as suggested in the blog post you sent. https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html. If the user is offline, I obviously can’t be sure that I will have the freshest copy. But suppose I am ok with that because users will only be working with their own data and only on their own device. In that case, does it help to use keepSynced(true) on the path to the zoo? Or since the amount of data the user is working with is well, well under 10mb (the whole database right now is 300k for 10ish active users), can I just assume the cache will store the data in the zoo path (whether keepSynced or not) because we never flirt with the 10mb limit in any case?
Thank you!

How to use NSCache appropriately in iOS application?

I am building an application and want to use NSCache to store data for caching.
There will be approx 5 API for which I need to cache data. Should I user NSCache? I did research for NSCache but I have some doubts regarding this.
I did go through below link.
https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/CachingandPurgeableMemory.html
I found some interesting things there.
NSCache provides two other useful "limit" features: limiting the number of cached elements and limiting the total cost of all elements in the cache. To limit the number of elements that the cache is allowed to have, call the method setCountLimit:. For example, if you try to add 11 items to a cache whose countLimit is set to 10, the cache could automatically discard one of the elements.
If we set limit to 10 and if we try to add 11th item then which particular item it will discard that is 1st one or 10th one? Or it can be a random item.
If I want to store 5 different NSCache object for all APIs then how can I do it?
I should make 5 different NSCache objects or I should store 5 different dictionary in single NSCache object?
Please let me know the best way to deal with it.
NSCache works basically as an NSMutableDictionary, the main difference is that even if is mutable is thread safe (usually mutable NSFoundation objects are not thread safe). So you get and set objects using keys.
Yes, the documentation is not clear, but I remember (and it makes sense) that is written that you should always detect if an object is cache and if not reload it from your primary source or manage that particular case. So it is not very important which one is removed, just make sure that at some point an object can not be there anymore and you are managing that situation.
I usually create different caches based on different context, but most of the time one would suffice.
I have few advices:
Your answer is tagged as Swift, thus pay attention that NSCache (in swift 2, don't know in 3) works only with objects and not struct or enumerations (value types unless thay can be bridged).
Remember that http protocol has its own cache system and communication, do not reinvent the wheel

IOS Core Data Fetch LAST object from Entity?

I'm not finding a reference to "Last" so I'll ask what I hope is a fairly simple need to fulfill. I have objects in a core data entity. Currently I do not implement any sort of "time stamp" on this entity which would not help much anyway because the users travel coast to coast but I suppose I could always stamp in zulu time.
I need to retrieve the LAST object that was added to refer to an attribute's value. I know core data stores it's own unique incrementing "key" but I don't know how to reference it. I need to check to see if the odometer reading the user is trying to enter is less then the last one entered or varies beyond normal bounds to check for user input error before saving a new object and present an alertview if so.
I can't look for #MAX because the user may have made an erroneous high entry prior. but I can deal with that issue separately once the user has determined he has made an invalid entry somewhere that needs to be addressed and dealt with accordingly.
Thanks.

Is there reason to create multiple instances of Ogre::RaySceneQuery for same scene?

I wonder if there are any benefits if i use multiple instances of Ogre::RaySceneQuery for same scene. Or if there are any things that requires it's own special instance?
Usually you only perform one query at one time, so there's no need to use a new RSQ instance each time.
Even if you're doing multiple types of queries you have to give the RSQ a new ray each time, so there won't be any difference if you do this using one or more instances.
Usually the code looks something like this:
Ogre::SceneManager* mSceneMgr;
Ogre::Ray ray; //whatever you want to query
Ogre::RaySceneQuery* mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
mRaySceneQuery->setRay(ray);
Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
//loop through the result
For each new ray you want to test you have to give the RSQ the new ray. Usually the rays are dependent on some coordinates (the player, the camera, ...) and you have to update the rays each iteration.
In case you have a static ray, a ray which doesn't depend on something and will be the same vector each and every iteration you may save the call to setRay(Ogre::Ray) if you use another RSQ instance for this specific ray only, but i doubt that this will be a huge performance boost or even noticeable as you still have to execute the query.
There's another point you should consider: query masks.
Every entity can have a binary mask which determines if it can get hit by a ray query.
Let's suppose you have this structure
enum QueryFlags {
FRIENDS = 1<<0;
FOES = 1<<1;
}
and every frame you wanna test if something hit a friend and/or a foe. There are a few possibilities:
You may check for both at once with mRaySceneQuery->setQueryMask(FRIENDS | FOES) and check every retrieved result if it is a friend or a foe.
You may execute two queries, one for FRIENDS and a second for the FOES.
You may use two RSQs, one for the friends and a second for the foe. This way you save a call to setQueryMask each time. As above I doubt this will give a significant performance gain, but I prefer the last option.

AS2: Duplicate movieclip to new layer

Ok, I know layers dont exist once compiled and that duplicated movieclips cannot be duplicated to new levels but I need some kind of work around here.
I cannot use the library as the movieclip I am duplicating is dynamically generated by actionscript (a graph based on user input over time) and thus cannot be made by me beforehand as it varies.
I need to somehow make a duplicate of this on a layer above the where the original was made, anyone know how this is possible?
Sort of irrelevant now, I had an array of coords from my original production of the movieclip and just decided to use that to create another with() the higher leveled mc.

Resources