Daily Archives

Articles indexed Sunday April 25 2010

Page 11/72 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • [Android] For-Loop Performance Oddity

    - by Jack Holt
    I just noticed something concerning for-loop performance that seems to fly in the face of the recommendations given by the Google Android team. Look at the following code: package com.jackcholt; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); loopTest(); finish(); } private void loopTest() { final long loopCount = 1228800; final int[] image = new int[8 * 320 * 480]; long start = System.currentTimeMillis(); for (int i = 0; i < (8 * 320 * 480); i++) { image[i] = i; } for (int i = 0; i < (8 * 320 * 480); i++) { image[i] = i; } Log.i("loopTest", "Elapsed time (recompute loop limit): " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (int i = 0; i < 1228800; i++) { image[i] = i; } for (int i = 0; i < 1228800; i++) { image[i] = i; } Log.i("loopTest", "Elapsed time (literal loop limit): " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); for (int i = 0; i < loopCount; i++) { image[i] = i; } for (int i = 0; i < loopCount; i++) { image[i] = i; } Log.i("loopTest", "Elapsed time (precompute loop limit): " + (System.currentTimeMillis() - start)); } } When I run this code I get the following output in logcat: I/loopTest( 726): Elapsed time (recompute loop limit): 759 I/loopTest( 726): Elapsed time (literal loop limit): 755 I/loopTest( 726): Elapsed time (precompute loop limit): 1317 As you can see the code that seems to recompute the loop limit value on every iteration of the loop compares very well to the code that uses a literal value for the loop limit. However, the code that uses a variable which contains the precomputed value for the loop limit is significantly slower than either of the others. I'm not surprised that accessing a variable should be slower that using a literal but why does code that looks like it should be using two multiply instructions on every iteration of the loop so comparable in performance to a literal? Could it be that because literals are the only thing being multiplied, the Java compiler is optimizing out the multiplication and using a precomputed literal?

    Read the article

  • Smart subdomain routing via reverse proxy

    - by Trevor Hartman
    I have two servers on my home network: OSX Server and an Ubuntu Server. I'd love to have external subdomains osx.mydomain.com point to osx and ubuntu.mydomain.com point to ubuntu. I know the normal way to do this is to have a static external IP address for each, but that's not an option as this is just my home setup. My question is: is there a way to do this with some reverse proxy trickery? OSX is currently the default entry point for all traffic. I was able to setup a reverse proxy on OSX for ubuntu.mydomain.com on port 80, so web traffic was correctly being proxied to my ubuntu. I'd like to ssh and do a bunch of other stuff though!

    Read the article

  • Win32: BitTest, BitTestAndComplement, ... <- How to disable this junk?

    - by Mordachai
    WinNT.h has the following lines in it, in the VS2008 SP1 install: #define BitTest _bittest #define BitTestAndComplement _bittestandcomplement #define BitTestAndSet _bittestandset #define BitTestAndReset _bittestandreset #define InterlockedBitTestAndSet _interlockedbittestandset #define InterlockedBitTestAndReset _interlockedbittestandreset I have a number of templates that are based on BitTest<() Does anyone know of a simple way to disable these #defines? Oftentimes MS does provide a #define XXX symbol which, if defined, will disable some offending portion of their header - e.g. NOMINMAX. I have been unable to find such a solution to the above problem. If you share frustration with Microsoft's many dubious choices, the read on. If not, stop here. ;) Editorializing: Why couldn't Microsoft just use the _bittest itself??? Or why couldn't they use BITTEST like every knows you should - always use all-caps for macros! Microsoft is still #defining things in 2010?! WTF?

    Read the article

  • Generics and Constrained Polymorphism versus Subtyping

    - by Rahul G
    Hullo all. In this (Warning: PDF) presentation on Haskell Type Classes, on slide #54, there's this question: Open Question: In a language with generics and constrained polymorphism, do you need subtyping too? My questions are: How do generics and constrained polymorphism make subtyping unnecessary? If generics and constrained polymorphism make subtyping unnecessary, why does Scala have subtyping?

    Read the article

  • c++ meaning of the use of const in the signature

    - by jbu
    Please help me understand the following signature: err_type funcName(const Type& buffer) const; so for the first const, does that mean the contents of Type cannot change or that the reference cannot change? secondly, what does the second const mean? I don't really even have a hint. Thanks in advance, jbu

    Read the article

  • php MySQL snytax error

    - by Jacksta
    my scrip is supposed to look up contacts in a table and present thm on the screen to then be edited. however this is not this case. I am getting the error Parse error: syntax error, unexpected $end in /home/admin/domains/domain.com.au/public_html/pick_modcontact.php on line 50 NOTE: this is the last line in this script. <? session_start(); if ($_SESSION[valid] != "yes") { header( "Location: contact_menu.php"); exit; } $db_name = "testDB"; $table_name = "my_contacts"; $connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "SELECT id, f_name, l_name FROM $table_name ORDER BY f_name"; $result = @mysql_query($sql, $connection) or die(mysql_error()); $num = @mysql_num_rows($result); if ($num < 1) { $display_block = "<p><em>Sorry No Results!</em></p>"; } else { while ($row = mysql_fetch_array($result)) { $id = $row['id']; $f_name = $row['f_name']; $l_name = $row['l_name']; $option_block .= "<option value\"$id\">$l_name, $f_name</option>"; } $display_block = "<form method=\"POST\" action=\"show_modcontact.php\"> <p><strong>Contact:</strong> <select name=\"id\">$option_block</select> <input type=\"submit\" name=\"submit\" value=\"Select This Contact\"></p> </form>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Modify A Contact</title> </head> <body> <h1>My Contact Management System</h1> <h2><em>Modify a Contact</em></h2> <p>Select a contact from the list below, to modify the contact's record.</p> <? echo "$display_block"; ?> <br> <p><a href="contact_menu.php">Return to Main Menu</a></p> </body> </html>

    Read the article

  • Best Practise for Stopwatch in multi processors machine?

    - by Ahmed Said
    I found a good question for measuring function performance, and the answers recommend to use Stopwatch as follows Stopwatch sw = new Stopwatch(); sw.Start(); //DoWork sw.Stop(); //take sw.Elapsed But is this valid if you are running under multi processors machine? the thread can be switched to another processor, can it? Also the same thing should be in Enviroment.TickCount. If the answer is yes should I wrap my code inside BeginThreadAffinity as follows Thread.BeginThreadAffinity(); Stopwatch sw = new Stopwatch(); sw.Start(); //DoWork sw.Stop(); //take sw.Elapsed Thread.EndThreadAffinity(); P.S The switching can occur over the thread level not only the processor level, for example if the function is running in another thread so the system can switch it to another processor, if that happens, will the Stopwatch be valid after this switching? I am not using Stopwatch for perfromance measurement only but also to simulate timer function using Thread.Sleep (to prevent call overlapping)

    Read the article

  • objective-c Derived class may not respond to base class method

    - by zadam
    Hi, I have derived from a 3rd party class, and when I attempt to call a method in the base class, I get the x may not respond to y compiler warning. How can I remove the warning? Repro: @interface ThirdPartyBaseClass : NSObject {} +(id)build; -(void)doStuff; @end @implementation ThirdPartyBaseClass +(id) build{ return [[[self alloc] init] autorelease]; } -(void)doStuff{ } @end @interface MyDerivedClass : ThirdPartyBaseClass {} +(id)buildMySelf; @end @implementation MyDerivedClass +(id)buildMySelf{ self = [ThirdPartyBaseClass build]; [self doStuff]; // compiler warning here - 'MyDerivedClass' may not respond to '+doStuff' return self; } @end Thanks!

    Read the article

  • How to Inject code in c# method calls from a separate app

    - by Fusspawn
    I was curious if anyone knew of a way of monitoring a .Net application's runtime info (what method is being called and such) and injecting extra code to be run on certain methods from a separate running process. say i have two applications: app1.exe that for simplicity's sake could be class Program { static void Main(string[] args) { while(true){ Somefunc(); } } static void Somefunc() { Console.WriteLine("Hello World"); } } and I have a second application that I wish to be able to detect when Somefunc() from application 1 is running and inject its own code, class Program { static void Main(string[] args) { while(true){ if(App1.SomeFuncIsCalled) InjectCode(); } } static void InjectCode() { App1.Console.WriteLine("Hello World Injected"); } } So The result would be Application one would show Hello World Hello World Injected I understand its not going to be this simple ( By a long shot ) but I have no idea if it's even possible and if it is where to even start. Any suggestions ? I've seen similar done in java, But never in c#. EDIT: To clarify, the usage of this would be to add a plugin system to a .Net based game that I do not have access to the source code of.

    Read the article

  • Create a SSL certificate on Windows

    - by Ben Fransen
    Hi all, Since I'm very new to SSL certificates, and the creation and usage of them I figured maybe StackOverflow members can help me out. I'm from Holland, the common way of online payments is by implementing iDEAL. An online payment protocol supported by the major banks. I have to implement a 'professional' version. This includes creating a RSA private key. Based on that key I have to create a certificate and upload it to the webserver. I'm on a Windows machine and completely confused what to do. I took a look at the OpenSSL website, because the manual forwarded me to that website to get a SSL Toolkit. The manual provides two commands which have to be executed in order to create a RSA key and a certificate. The commands are: openssl genrsa -des3 –out priv.pem -passout pass:myPassword 1024 and openssl req -x509 -new -key priv.pem -passin pass:myPassword -days 3650 -out cert.cer Is there a way I can do this by a utility on a windows machine? I've downloaded PuTTy KeyGenerator. But I'm not sure what to do, I've created a key (SSH-2 RSA, whatever that is..) but how do I create a certificate with that key? Any help is much appreciated! Ben

    Read the article

  • Class type while deserialization in c++

    - by Rushi
    I am developing game editor in c++.I have implemented reflection mechanism using DiaSDK.Now I want to store state of the objects(Like Camera,Lights,Static mesh) in some level file via serialization. And later on able to retrieve their state via deserialization.Serializing objects is not a problem for me.But while deserializing objects how do I know class type?so that i can create object of that particular type.

    Read the article

  • C#: Abstract classes need to implement interfaces?

    - by bguiz
    My test code in C#: namespace DSnA { public abstract class Test : IComparable { } } Results in the following compiler error: error CS0535: 'DSnA.Test' does not implement interface member 'System.IComparable.CompareTo(object)' Since the class Test is an abstract class, why does the compiler require it to implement the interface? Shouldn't this requirement only be compulsory for concrete classes?

    Read the article

  • Dynamic Tab Implementation in ADF

    - by Vijay Mohan
    Well, this can be a common usecase across apps to open tabs dynamically at runtime based on the request.Well, in order to achieve this you can have a parent container, lets say a panelTab component.Inside panelTab , u can have a showDetailItem inside an af:foreach or an af:iterator binded to a bean static list which will have as many show detail items as you wish to be shown.something like this.private static List = { new showDetailItem("1"),new ShowDetailItem("2") ...};now in the backing bean you can have a method that takes care of rendering and disclosing an specific tab based on the index.public void openMyTab(){List<MyItems> list = refToParentContainer.getChildren();int indexOfTabToBeOpened = //Write a method that will compute the tab index of the next //tab.list.get(index).setRendered(true);list.get(index).setDisclosed(true);similarly you can set other properties too.}Else, instead of having af:foreach/iterator iterating through the SD items , you can go for static SDs in the page with render property set to false and then you can follow the same approach to render/disclose it at runtime.

    Read the article

  • Avoiding Mixup of Language Details

    - by DarenW
    Today someone asked me what was wrong with their source code. It was obvious. "Use double equals in place of that single equal in that if statement. Um, i think..." As i remember some languages actually take a single equals for comparison. Since i sometimes forget or mix up the syntax details among the several languages i use, i stepped over to my laptop to try a quickie experiment... It costs a bit of time and is a break in the flow to try "quick" experiments (though maybe the practice is good for memory.) What tips do you have for keeping straight in your mind the syntax (and other) details of multiple languages? (And nowadays, this applies just as well to the many wiki-like markups!)

    Read the article

  • unable to cope with the asynchronous nature of navigator.geolocation.

    - by Raja
    Hi all I'm using the navigator.geolocation.getCurrentPosition(function) api in firefox 3.6. When i try to call this method repeatedly I see that sometimes it works and sometimes it doesn't. I figured that the problem is because of its asynchronous callback nature. I can see that the callback function is being called at some point but my outer function is already exiting so i cannot catch the values of the position coordinates. I'm pretty new to javascript so i'm assuming other javascript coders might have already figured out how to deal with it. Please help. Thanks

    Read the article

  • FluentNHibernate - ClassMap vs IAutoMappingOverride

    - by Mendy
    In FluentNHibernate when should I use ClassMap and when IAutoMappingOverride<Entity> for my EntityMap classes. public class PostMap : ClassMap<Post> { public PostMap() { ... } } vs public class PostMap : IAutoMappingOverride<Post> { public void Override(AutoMapping<Post> mapping) { ... } }

    Read the article

  • why javascript can not read the cookie in asp.net ?

    - by MemoryLeak
    I want to read the sessionid in cookie which is automatically generated by asp.net. such as ASP.NET_SessionId. but when i use javascript: document.cookie = "ASP.NET_SessionId=;" since i want to set the ASP.NET_SessionId to be empty. but after the javascript executed, i found instead of change the ASP.NET_SessionId to empty, system generate a new cookie with ASP.NET_SessionId equal to empty. why system not modify the cookie but generate a new one ? Thanks!

    Read the article

  • By-name repeated parameters

    - by Green Hyena
    How to pass by-name repeated parameters in Scala? The following code fails to work: scala> def foo(s: (=> String)*) = { <console>:1: error: no by-name parameter type allowed here def foo(s: (=> String)*) = { ^ Is there any other way I could pass a variable number of by name parameters to the method?

    Read the article

  • Best way to get a query result

    - by xgoan
    I'm developing an application that gets large images from an Internet server which is the best way to download this images, without freeze the entire application? I mean background download. I have thought about download it in another thread.

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >