Here is a good example on why either you love C++ or hate it with such terse expression oriented code; I think its pretty cool.
If you want to copy one string to another, one option can be something like this.
void mycopy(char *p, char *q) {
int len = strlen(q);
for(int i=0; i<=len; i++)
p[i] = q[i];
}
However this achieves the same thing as above and is more efficient:
void mycopy(char *p, char *q) {
while(*p++ = *q++);
}
Of course why would you write your own version when you have standard string copy fundtion strcpy in <string.h>
Similar posts to check out:
- May 26, 2011 -- Troubleshooting WCF Performance – Part 1 (0)
More related details on Dustin's post - WCF scales up slowly with bursts of work.... - May 23, 2011 -- PowerShell script to kill named processes (0)
There are times when you need to kill a number of processes in one-go like today when Chrome crashed a few times hanging all the running instances – next time Google says, one tab cannot bring down all of them – send them my way :). For such times, a PowerShell script is all you need.
I wrote up a simple one which takes the process name as input and then kills all the processes which match that name.
[sourcecode lang="PowerShell" toolbar="true"]
#Script is not signed, so need this.
Set-... - March 4, 2011 -- Twitter Trends (0)
I was excited to find that Twitter had a JSON (Javascript Object Notation) endpoint for the current trending topics and decided to write a simple consumer which can read this and then spit it out in a simple console. And JSON being so simple and more or less “universal” meant that there are multiple implementations for .NET. Of course if you got lots of bandwidth you can roll out your own parser.
I ended up using Json.NET, which in addition to being OpenSource is also one of the most robust u...
Tags: .code