A common thing to want to do is to find zero values in an array. This is obviously necessary for string length. So we'll start out with a test harness and a...
A common thing to want to do is to find zero values in an array. This is obviously necessary for string length. So we'll start out with a test harness and a simple implementation:#include "timing.h"unsigned int len(char* array){ unsigned int length = 0; while( array[length] ) { length++; } return length;}#define COUNT 100000void main(){ char array[ COUNT ]; for (int i=1; i<COUNT; i++) { array[i-1] = 'a'; array[i] = 0; if ( i != len(array) ) { printf( "Error at %i\n", i ); } }...
A common thing to want to do is to find zero values in an array. This is obviously necessary for string length. So we'll start out with a test harness and a simple...
Hit a couple of issues with gedit, just documenting them in case others hit the same problems.X11 connection rejected because of wrong authentication.This...
Hit a couple of issues with gedit, just documenting them in case others hit the same problems.X11 connection rejected because of wrong authentication.This turned out to be because there was already a copy of gedit running on the system.GConf Error: Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See http://projects.gnome.org/gconf/ for information. (Details...
Hit a couple of issues with gedit, just documenting them in case others hit the same problems.X11 connection rejected because of wrong authentication.This turned out to be because there was already a...
Population count is one of the more esoteric instructions. It's the operation to count the number of set bits in a register. It comes up with sufficient...
Population count is one of the more esoteric instructions. It's the operation to count the number of set bits in a register. It comes up with sufficient frequency that most processors have a hardware instruction to do it. However, for this example, we're going to look at coding it in software. First of all we'll write a baseline version of the code:int popc(unsigned long long value){ unsigned long long bit = 1; int popc = 0; while ( bit ) { if ( value & bit ) { popc++; } bit...
Population count is one of the more esoteric instructions. It's the operation to count the number of set bits in a register. It comes up with sufficient frequency that most processors have a...
One question you might ask is "how much memory is my application consuming?". Obviously you can use prstat (prstat -cp <pid> or prstat -cmLp <pid>) to examine...
One question you might ask is "how much memory is my application consuming?". Obviously you can use prstat (prstat -cp <pid> or prstat -cmLp <pid>) to examine the behaviour of a process. But how about programmatically finding that information.OTN has just published an article where I demonstrate how to find out about the resource use of a process, and incidentally how to put that functionality into a library that reports resource use over time.
One question you might ask is "how much memory is my application consuming?". Obviously you can use prstat (prstat -cp <pid> or prstat -cmLp <pid>) to examine the behaviour of a process. But how about...
Functions declared as inline are slightly more complex than might be expected. Douglas Walls has provided a chapter-and-verse write up. But the issue bears...
Functions declared as inline are slightly more complex than might be expected. Douglas Walls has provided a chapter-and-verse write up. But the issue bears further explanation.When a function is declared as inline it's a hint to the compiler that the function could be inlined. It is not a command to the compiler that the function must be inlined. If the compiler chooses not to inline the function, then the function will be left with a function call that needs to be resolved,...
Functions declared as inline are slightly more complex than might be expected. Douglas Walls has provided a chapter-and-verse write up. But the issue bears further explanation.When a function...
Bit manipulation is one of those fun areas where you can get a performance gain from recoding a routine to use logical or arithmetic instructions rather than a...
Bit manipulation is one of those fun areas where you can get a performance gain from recoding a routine to use logical or arithmetic instructions rather than a more straight-forward code.Of course, in doing this you need to avoid the pit fall of premature optimisation - where you needlessly make the code more obscure with no benefit, or a benefit that disappears as soon as you run your code on a different machine. So with that caveat in mind, let's take a look at a simple...
Bit manipulation is one of those fun areas where you can get a performance gain from recoding a routine to use logical or arithmetic instructions rather than a more straight-forward code.Of course, in...
Over at the OTN Garage, Rick has published details of the Solaris Studio hands-on lab.This is a great chance to learn about the Code Analyzer and the...
Over at the OTN Garage, Rick has published details of the Solaris Studio hands-on lab.This is a great chance to learn about the Code Analyzer and the Performance Analyzer. Just to quickly recap, the Code Analyzer is really a suite of tools that do checking on application errors. This includes static analysis - ie extensive compile time checking - and dynamic analysis - run time error detection. If you regularly read this blog, you'll need no introduction to the Performance...
Over at the OTN Garage, Rick has published details of the Solaris Studio hands-on lab.This is a great chance to learn about the Code Analyzer and the Performance Analyzer. Just to quickly recap,...
Thought I'd highlight this error message:class foo{ foo();}foo::foo() { }$ CC -c c.cpp"c.cpp", line 6: Error: A constructor may not have a return type...
Thought I'd highlight this error message:class foo{ foo();}foo::foo() { }$ CC -c c.cpp"c.cpp", line 6: Error: A constructor may not have a return type specification.1 Error(s) detected.The problem is that the class definition is not terminated with a semi-colon. It should be:class foo{ foo();}; // Semi-colonfoo::foo() { }
Thought I'd highlight this error message:class foo{ foo();}foo::foo() { }$ CC -c c.cpp"c.cpp", line 6: Error: A constructor may not have a return type specification.1 Error(s) detected.The problem is...
There's an interesting corner case in the behaviour of std::list::splice. In the C++98/C++03 standards it is defined such that iterators referring to the...
There's an interesting corner case in the behaviour of std::list::splice. In the C++98/C++03 standards it is defined such that iterators referring to the spliced element(s) are invalidated. This behaviour changes in the C++11 standard, where iterators remain valid.The text of the 2003 standard (section 23.2.2.4, p2, p7, p12) describes the splice operation as "destructively" moving elements from one list to another. If one list is spliced into another, then all iterators and...
There's an interesting corner case in the behaviour of std::list::splice. In the C++98/C++03 standards it is defined such that iterators referring to the spliced element(s) are invalidated. This...