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
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
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
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
It should be noted that MSVC uses the syntax: #pragma message ( “your warning text here” ) The usual #warning syntax generates a fatal error C1021: invalid preprocessor command ‘warning’ so it is not portable to those compilers.
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
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
IIRC, In GCC you can provide the –stack,[bytes] parameter to ld. E.g. gcc -Wl,–stack,16777216 -o file.exe file.c To have a stack of 16MiB, I think that the default size is 8MiB.
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
First off, the only way to actually answer performance questions is to actually try it both ways and test the results in realistic conditions. That said, the other answers which say that “the compiler” does not do this optimization because the property might have side effects are both right and wrong. The problem with the … Read more