Understanding return value optimization and returning temporaries – C++

In two first cases RVO optimization will take place. RVO is old feature and most compilers supports it. The last case is so called NRVO (Named RVO). That’s relatively new feature of C++. Standard allows, but doesn’t require implementation of NRVO (as well as RVO), but some compilers supports it. You could read more about … Read more

Does concatenating strings in Java always lead to new strings being created in memory?

I realized that the second way uses string concatenation and will create 5 new strings in memory and this might lead to a performance hit. No it won’t. Since these are string literals, they will be evaluated at compile time and only one string will be created. This is defined in the Java Language Specification … Read more

Which C99 features are available in the MS Visual Studio compiler?

Fortunately, Microsoft’s stance on this issue has changed. MSVC++ version 12.0 (part of Visual Studio 2013) added support for _Bool type. Compound literals. Designated initializers. Mixing declarations with code. __func__ predefined identifier. You can check the _MSC_VER macro for values greater than or equal to 1800 to see whether these features are supported. Standard library … Read more

JIT compiler vs offline compilers

Yes, there certainly are such scenarios. JIT compilation can use runtime profiling to optimize specific cases based on measurement of the characteristics of what the code is actually doing at the moment, and can recompile “hot” code as necessary. That’s not theoretical; Java’s HotSpot actually does this. JITters can optimize for the specific CPU and … Read more

Adding scripting functionality to .NET applications

Oleg Shilo’s C# Script solution (at The Code Project) really is a great introduction to providing script abilities in your application. A different approach would be to consider a language that is specifically built for scripting, such as IronRuby, IronPython, or Lua. IronPython and IronRuby are both available today. For a guide to embedding IronPython … Read more

Why does Java switch on contiguous ints appear to run faster with added cases?

As pointed out by the other answer, because the case values are contiguous (as opposed to sparse), the generated bytecode for your various tests uses a switch table (bytecode instruction tableswitch). However, once the JIT starts its job and compiles the bytecode into assembly, the tableswitch instruction does not always result in an array of … Read more

On-the-fly, in-memory java code compilation for Java 5 and Java 6

JCI looks fine. This code snippet should be your base: JavaCompiler compiler = new JavaCompilerFactory().createCompiler(“eclipse”); MemoryResourceReader mrr = new MemoryResourceReader(); mrr.add(“resource name string”, yourJavaSourceString.getBytes()); MemoryResourceStore mrs = new MemoryResourceStore(); CompilationResult result = compiler.compile(sources, mrr, mrs); // don’t need the result, unless you care for errors/warnings // the class should have been compiled to your destination … Read more