I develop a simulator in Unity which has to communicate with another application. The problem is that I have to render a camera manually and send the obtained image to the other application, which takes too long.
My question: is there a way to get the memory address where the obtained image is? I need this to read the image directly from the other application in order to reduce the time of the transmission.
Related
Whats the most effective way of dealing with different image resolutions in Parse for the different ios devices?
For instance
Would it be better to have 1 image in parse at the highest res and download for every device? (slower download speeds for lower res devices)
Have 1x 2x and 3x versions of the image in Parse and download for relevant device. (takes up more storage space on Parse)
Run cloud code on Parse to resize the images to their correct resolution as they are downloaded to the devices. (possible slower download speed for all devices?)
Any other options anyone can think of would be welcome.
Al
I would say this strongly depends on the usage case. For example, if you have a profile picture, I would recommend uploading it in 2-3 versions, as those pictures may be downloaded very often (for example in a social networking app where you have profile pictures in posts, user profiles, messages, etc.). When the picture is downloaded a high amount of times, you would rather download a smaller one to minimise download time and save parse data transfer resources.
On the other hand, for pictures that aren't downloaded as often as other ones, I'd recommend storing them in a high-res format, and scaling them down (if necessary) as they are downloaded. Take for example again a social networking app. A post contains a profile picture (which is downloaded quite often) and the actual post (a photo in this case). The actual post photo is only downloaded a single time (ideally), so there should be no reason to worry about the download speed.
Basically (and that's the way I handle this), you should always try to cache every image. Images that can be cached easily and don't have to be retrieved very often can be stored in a single high-res format (saving data space on parse). Images that cannot be cached easily or have to be refreshed quite often, should be stored in different sizes, which will, in the end, save you data transfer. The small amount of extra storage does not have that much impact, to be honest, especially if you store them in scaled down sizes.
In my application I need to read data from an input stream. I have set the current buffer size for reading as 1024. But I have seen in some Android applications buffer size has been kept as 8192 (8 KB). Will there be any specific advantage if I increase the buffer size in my application to 8KB?
Any expert opinion will be much appreciated.
Edit: (I am using BB OS 6 and 7 and I am dealing with network inputstream.)
I can't say that I've found the universally best buffer size, but it seems to me that something in the range of 1KB to 8KB should be fine in most situations (for BlackBerry Java apps).
Keep in mind that if the amount of data is small (so you'd probably only need one or two buffers at 1KB-8KB), it's probably best just to use the IOUtilities method:
byte[] result = IOUtilities.streamToBytes(inputStream);
with which you don't need to actually pick a buffer size. But, if you know that result would be a large block of data, you're probably right in wanting to read one buffer at a time.
However, I would argue that the answer should almost always be obtained simply by building the app, and measuring performance with a few different values for byte buffer size. It's easy enough to change one constant, build, run and measure again, and then you're not guessing, or taking the advice of someone who doesn't know all the details of your app.
See here for information about BlackBerry Eclipse plugin memory analysis, and
here for BlackBerry Eclipse plugin profiling.
These tools are found in Eclipse by selecting the Window menu, then Show View -> Other... -> BlackBerry -> BlackBerry Memory Statistics View, or BlackBerry Profiler View, while debugging.
This way, you can see how much memory, or processor, the network code is using during the call to retrieve data and populate your buffer.
More
BlackBerry InputStream to String conversion
This question was also asked in the official BlackBerry forum here:
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-best-size-for-a-buffer-in-BlackBerry/td-p/2559417
The OP gave this clarification:
"I am reading from network. Once I establish socket connection with the server, the server will send me notifications one after the other. I need to read the notifications/data from the inputstream available in the socket connection. For this I have a background thread which checks anything is available in the inputstream and if something is available, it will read with the help of a buffer and then passes the read data to a StringBuffer."
Given this information, I have a different take, in that I think the BlackBerry network handling abstracts the Java application from the network buffer processing to the extent that the application buffer size will have little if any impact on the performance.
But be aware, this is only my opinion.
My response on that thread was as follows:
First thing to note is that the method "isAvailable()", in my experience, does not work correctly on OS 5.0 and earlier. It is fixed in OS 6 (at least from my testing).
Because isAvailable() was broken, (and for other application reasons) what I have implemented for a socket connection is that each message is preceded by a length. So in the socket connection, I read the length of the next message, and then the actual data. This is done with no blocking - in other words I read the entire message, regardless of size. I recommend you do the same. The message must exist in full somewhere so it makes no difference if it is in some memory managed by the socket connection, or in some memory managed by you.
Note also, until OS 6.0, when you did the read you would get all the data to fill the buffer you had - in other words it waited till the buffer was full. In OS 6.0 and later, the read can complete without giving you a full buffer.
In your case, you might be working in a post OS 6.0 only, so you could use isAvailable() - create a buffer of that size, and read everything. I can't see that it makes any difference whether you have the bytes in memory managed by the socket, or memory managed by you.
But in fact, I would argue that the best approach is the one that makes your processing simplest. So for example, if you know that the next message is 200 bytes, then read 200 bytes, and then process that message. Then read the next message.
You could spend a lot of time attempting to manage the buffers to match the underlying socket buffers. I don't know exactly how the underlying BlackBerry socket processing code works, but it doesn't put data directly into your buffers. So let it manage its buffer size to optimize the network, you manage your buffer size to optimize your processing. That will work best for everyone.
I am working on an IOS app that will display images uploaded by user from my website.
What is the best practices on re-sizing the images on mobile or server?
Option A - Resize thumbnail, desired size and stored it on a cloud server, Amazon S3 for example which host images for iphoneretina_ImgA, Iphone_ImgA, Ipad_ImgA, IphoneThumbnail_ImageA.
Option B - Resize to thumbnail, desired size on the device.
What is the best approach on displaying server image to iphone/ipad devices?
You will get optimal performance on the device if you can do as much image processing on the server-side as possible and deliver optimally sized images to the device (i.e. smallest possible image to support the desired user interface), which will save not only download time (esp if user is on slower cellular networks) but also precious device memory and processing time (if you download high resolution images to device, the amount of CPU cycles and memory required to convert them to appropriate sized images or, worse, not resize them and try to let the poor ol' UIImageView try to render them).
In short, if you can do it server-side, that's ideal. If you do it on the device you'll suffer network bandwidth, memory consumption, and processing time on the device.
If the original images aren't too big, though, you can get away with some reasonable compromises which entail a modest device-side processing. For example, I'm interfacing with a legacy CMS system with modestly sized images and limited existing server-side image processing capabilities, so I just make my thumbnails on the device lazily as they're downloaded/required, but (a) the original images weren't huge; (b) I needed the original resolution images on the device anyway; and (c) I had to do some clever GCD (or you can use some other equivalent concurrent processing technology) to make sure the user interface wasn't too noticeably impacted as the app does one-time thumbnail generation (thumbnails that are then cached locally for optimal performance in the future).
As always in these cases, your final architecture will be a function of the particulars about your images, your server capabilities, the app requirements, but, if there's any rule of thumb, it would be do as much server-side as you can, balancing network bandwidth and server complexity issues with other demands on the device.
Firstly, the following thread discusses the issue that toDataURL may increase memory consumption, but doesn't offer a way to use toDataURL safely:
javascript memory leak with HTML5 getImageData
In my application, I need to call toDataURL. I have a PhoneGap application running on IOS that take photos using the native camera, tiles the images together into one collage image, and sends the final image as a binary 64 string via ajax post to a server. The part of my code that tiles the images uses an html canvas and toDataURL to accomplish that. This tiling occurs repeatedly over the lifetime of the software process. I am seeing the application memory increase until IOS aborts the process.
What would you recommend to do to be able to call toDataURL but not run out of memory? I don't see how to release this memory.
Thanks.
Instead of trying to memory manage, it may just be easier to send the independent images to the server and let the server create the collage for you.
I have a question on using the AssetLibrary with iOS. It it possible to store a pointer to an image in your app rather than the actual image? Let's say I want to create a playlist, but I don't want to store the actual image.
The reason I am asking, is that I find when I use the image picker, I can save an image to the devices documents directory, but once I get to 25 or so, it starts to slow down the device (iPad 1). I scale down the images if they are very large, I ran through the leaks instrument many times, and there are no leaks. I am just at a loss as to where to turn next, so I wanted to investigate alternatives. As I see nowhere where I can free up memory.
That's where I am at now, I'm curious if the AssetLibrary might be a option since I won't be storing physical images. I know it has some dis-advantages (requires users location, can be a bit slow when looping through images)
Any thoughts on this would be greatly appreciated.
Storing 25 images to the documents directory shouldn't slow down the device, unless you're trying to load all 25 extremely large images into memory at the same time.
You can't permanently store a pointer to the assets library asset, but you can store the URL you retrieve from the ALAssetRepresentation's url property and then use ALAssetsLibrary's assetForURL:resultBlock:failureBlock: to get back the corresponding ALAsset later. Do note that it is possible for the user to delete the asset from outside your program, even when your app is in the background, so if you are hanging on to an ALAsset you must listen for ALAssetsLibraryChangedNotification to know when to reload the assets.