Search
Search the archive with full-text matching across story titles, bodies,
and comments. Phrases are quoted; or, -word,
and parentheses behave as in a web search. Queries must be at least
3 characters.
Stories · 615
-
Arrays vs Pointers in C?
UOZaphod asks: "A recent sub-discussion on Slashdot (in which, I confess, I was involved) piqued my curiosity because of several comments made about C compiler optimizations. I was informed that said optimizations have made it so that indexing an array with the [] operator is just as fast as using an incremented pointer. When the goal is maximum performance across multiple CPU architectures, can one always assume that this is true?" "Here are my own thoughts on the issue:
For discussion purposes, I present the following two equivalent functions which reverse the contents of a string. Note that these code fragments are straight C, and do not account for MBCS or Unicode.
The first function uses array indexing:void reversestring_array(char *str)
The second function uses pointers:
{int head, tail;
}
char temp;
if (!str) return;
tail = strlen(str) - 1;
for (head = 0; head < tail; ++head, --tail)
{temp = str[tail];
}
str[tail] = str[head];
str[head] = temp;
void reversestring_pointer(char *str)
While there are obvious optimizations that could be done for both functions, I wanted to keep them as simple and semantically similar as possible.
{char *phead, *ptail, temp;
}
if (!str) return;
ptail = str + strlen(str) - 1;
for (phead = str; phead < ptail; ++phead,--ptail)
{temp = *ptail;
}
*ptail = *phead;
*phead = temp;
Arguments have been made that the compiler will optimize the first example using register indexing built into the CPU instruction set, so that it runs just as fast as the pointer version.
My argument is that one cannot assume, in a multi-architecture environment, that such optimizations will always be available. Semantically, the expression array[index] must always be expanded to *(array + index) when the index is variable. In other words, the expression cannot be reduced further, because the value of the index is unknown at run time.
Granted, when I compiled the above examples on an x86 machine, the resulting assembly for each of the two functions ended up looking very similar. In both cases, I enabled full compiler optimization (Pentium Pro). I will present just the inner loop for each function...
The array function:forloop:
The pointer function:
mov bl,byte ptr [esi+edx]
mov al,byte ptr [ecx+edx]
mov byte ptr [ecx+edx],bl
mov byte ptr [esi+edx],al
inc esi
dec ecx
cmp esi,ecx
jl forloopforloop:
While this example appears to prove the claim that compiler optimizations eliminate the differences between array and pointer usage, I wonder if it would still be true with more complicated code, or when indexing larger structures.
mov bl,byte ptr [ecx]
mov dl,byte ptr [eax]
mov byte ptr [eax],bl
mov byte ptr [ecx],dl
inc ecx
dec eax
cmp ecx,eax
jb forloop
I'd certainly be interested in hearing more discussion on the matter, accompanied by examples and references." -
Office 12 Exposed
damieng writes "The Programmers Developer Conference (PDC) has unveiled the user interface for Microsoft Office 12. Bearing more than a passing resemblance to Aqua and brushed metal looks from Mac OS X the menus now appear to operate more like a tab popping-out the right toolbar instead of a sub-menu."
-
Best TCP/IP Stack Implementation?
paultantk asks: "This mailing list suggests that the FreeBSD TCP/IP stack is sub-par. It was the best in the 90's, but not anymore. So the question is, which operating system now holds the title for the best TCP/IP stack implementation?"
-
Mathematical Atlas Online
vitaly.friedman writes "Whether you are looking for Complex analysis, Differential Equatiions or Probability and Statistics references, the Mathematical Atlas covers the whole area of mathematics and related subjects. The so-called 'Gateway to Mathematics' is a collection of articles about aspects of mathematics at and above the university level, but (usually) not at the level of current research. "The goal of this collection is to introduce the subject areas of modern mathematics, to describe a few of the milestone results and topics, and to give pointers to some of the key resources where further information is to be found. Like any good atlas, we try to present several ways to look at each area and to show its relationship with neighboring areas and sub-areas."
-
BLAST High Altitude Telescope Launched
Xandu writes "BLAST, the Balloon-borne Large Aperture Sub-millimeter Telescope, was launched on the 11th at 11:09 UTC from Esrange in northern Sweden, and is currently floating over Greenland. BLAST is a 2700kg telescope with a 2 meter primary mirror that hangs from a 1.1 million m^3 balloon floating at an altitude of 38km that will study the star formation history of the universe. It will float west at nearly constant latitude for about 5 days before the flight is terminated over northwest Canada or northern Alaska. Real time position and flight track is available from the NSBF. Two of the graduate students working on the project have photo blogs of the entire (8 week) prep period, including several launch photos. The press has more traditional coverage as well. And if that isn't geeky enough to make it on Slashdot, the flight computers run Slack."
-
360's Backwards Compatibility Weak?
GamesIndustry.biz is reporting that the backwards compatibility that Microsoft offered up at the Monday press conference may not be anything approaching what we're used to. Due to the massive design changes in the shift from the Xbox to the 360, Xbox titles may have to be recompiled in order to work on the next-gen console. From the article: "The news has raised more questions than it answers, however, as it suggests that gamers may need to purchase titles they already own in order to play them on an Xbox 360 - and almost certainly means that only a sub-set of Xbox games will ever be playable on the new console." Update: 05/20 15:08 GMT by Z : The article has been updated with a quote from MS specifically saying that gamers will *not* need to repurchase Xbox titles to play them on the 360.
-
How to Cool Your PC with Dry Ice
Ant writes "This Madshrimps article is a complete guide to working with dry ice so you can reach sub-zero temperatures with your CPU and graphics card. Details on building containers, where to buy dry ice and important tips and tricks. (Seen on Blue's News.)"
-
RFC On New Internet Routing Protocol
PoesRaven writes "An A. Farrel has put out a Request For Comments paper on a new routing protocol with profound implications for the internet, the usability of the TCP/IP protocol, and the security of the net's youngest users. From the RFC: "It has often been the case that morality has not been given proper consideration in the design and specification of protocols produced within the Routing Area. This has led to a decline in the moral values within the Internet and attempts to retrofit a suitable moral code to implemented and deployed protocols has been shown to be sub-optimal." Interesting, but seems to raise some serious privacy questions.
-
SF RoboGames This Weekend
Vrogy writes "RoboGames (formerly RoboOlympics) kicked off on Friday in San Francisco with competitor check in and sub-Lightweight class fights. This competition, following in the footsteps of events such as Robot Wars and Battlebots, pits remotely-controlled fighting machines against each other in a bulletproof steel arena. The Competitors are many and tickets are still available. Saturday and Sunday will feature up to 340, or Superheavyweight robot combat, with such crowd favorites as Alcoholic Stepfather, a superheavy that spews flame nearly 25 feet, and Megabyte, a heavyweight that spins a steel shell of doom. RoboGames isn't only for fighting robots, though, it will also feature miniature robotic wrestlers called Robo-Ones, Lego bots, BEAM bots, robotic soccer games, and all kinds of art bots- it's like a festival of robots!"
-
Star Wars Revelations - May the Force Be With You!
n0alpha writes "For all you Star Wars fans out there, if you've been less than satisfied with the last two episodes of Star Wars, fear not. There is a new episode coming out soon -- but I'm not talking about Revenge of the Sith. On April 16th, 2005 the world will be blessed with a brand new episode, Star Wars Revelations. This is an independent film, completely put together by volunteers and organized by Panic Struck Productions, but don't let that fool you into thinking it is sub-par. Visit their website to view a trailer."
-
Rappers the Next Super Heroes?
The Guardian's excellent gamesblog has an editorial up discussing the role rappers and rap culture has taken in games. From the article: "Following Def Jam Vendetta and more pertinently Def Jam Fight for New York, this is another game that places real-life Hip Hop artists within a fictitious gangland setting. It's an interesting sub-genre, trading in on the mythologies that many rappers build around themselves in their lyrics, album art and endless feuds - fantasies of gun violence, rivalry and retribution."
-
Retailers Deploy Databases Against Customers
A couple of people submitted this piece about retailers using databases to crack down on sub-optimal customers, such as those who return too many purchases to the store. Also has a few tidbits about other database blacklists that are available to companies. Customers avoid intrusive practices; although this story was written by the Washington Post and I have the URL to the original story available, I declined to link to washingtonpost.com because of their intrusive registration.
-
The Cult of Mac
cgjherr (Jack Herrington) writes "The Cult of Mac, a new book by Leander Kahney, is a love letter to the Macintosh community. The book seeks to simultaneously define and evangelize the Apple cultural phenomenon. With 25 million users (in the author's estimation) there is a lot of culture to go around. The tattoos. The modified machines. The pilgrimage to MacWorld. The sub-cult of iPod. It's all here." Read on for the rest of Herrington's review. The Cult of Mac author Leander Kahney pages 268 publisher No Starch rating Excellent reviewer Jack Herrington ISBN 1886411832 summary A love letter to the Mac community
The form and structure of the book is a cross between a Wired magazine (for which Kahney has long written on Apple) and a coffee table book. There are great pictures of people, machines and art to appeal to the eye. Some pages are all pictures, while others are primarily text -- most are a combination of the two. The layout is always attractive. If this were a book from Apple, the style would be cleaner and there would be less emphasis on the past; this book is from and for the fans, though, so the style is more edgy and chaotic.
The book is divided into five large sections. The first covers the Macintosh itself, its users, its evangelists, and a little of its history. Including, to my amusement, but not surprise, its connection with pot, which occupies three pages. Wozniak is covered lovingly, and Jobs is painted with the same awe, love and hate brush that the community uses. Leander even covers the TV and movie Macintosh spotting, where the good guys always use Macs and the bad guys always use PCs.
Section two takes us into the MacWorld phenomenon. The secrecy, the crazy crowds, the keynote -- the whole shebang. We also get a look into the Mac phenomenon in Japan.
The final three sections are the most interesting to the hardware lovers. Section four covers modifying the Macintosh, futuristic designs, and the variety of things that have been built from dead Macs. The fourth section is about collecting Macintoshes; there is an excellent image here of a reception desk built entirely of old Mac Classics. Some attention is also paid to the devotees of Apple tsotchkes -- the shirts, the pins, the shoes, and other logo-branded novelties.
The final section is all about what comes next. Here Leander covers the iPod and its subculture, as well as the ongoing cultural battle between Microsoft users and the Mac world. The author even goes so far as to associate the construction of the swivel head iMac to that of a newborn baby to justify our attachment to it. And that makes my Powerbook a what?
There is a lot of great material in this book just to flip through, or to sit down for an enjoyable read. For the technically minded, there is nothing here to help you write better code or get more out of the operating system. This is a book about a culture, its icons, its people, and its ideology.
I can't recommend this book for a PC person, Unless he's interested in learning about the phenomenon or becoming part of it, I doubt there is much he'd interesting in this book. A PC user uses his machine to perform a task and thinks little of the machine itself. A Mac, on the other hand, is a key component of an integrated lifestyle. If you don't live the lifestyle and you care to know more about it, then check out the book. Otherwise, you might as well skip it.
As a Mac enthusiast myself I really enjoy this book. I started programming on the Macintosh with the first 128K machine, took a hiatus on Windows for a couple of years, and switched back with OS X. I've been to a MacWorld and seen some of the phenomenon first-hand. But it's nice to see it catalogued here in such an attractive, nicely constructed, well-written book.
In the early days of Apple versus Microsoft we had a real culture war, command line versus GUI. Windows won. Which is bad because Mac is, IMHO, better. But the Windows victory does allow us in the Mac camp to revel in our own individuality. This book is a fun way for new and old Mac fans alike to share in the common insanity which is our somewhat unrealistic love for this computer and it's company.
I'm certainly glad this book came out before Christmas. Now I know what I am going to give a couple of my fellow Macaddicts.
Reviewer Jack Herrington authored Code Generation in Action, and edits the Code Generation Network. You can purchase The Cult of Mac from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, carefully read the book review guidelines, then visit the submission page. -
MySQL AB Calls v4.1.7 Production Ready
puppetman writes "MySQL announced a few hours ago that 4.1 has been deemed production ready with the release of 4.1.7. The major enhancements of 4.1 include sub-selects, faster communication between client and server (thanks to parameter binding), replication over SSL, and lots more. A full list can be found here. Time to rehash those tired arguments about why MySQL is not a real database, and (Postgres/Oracle/SQL Server/Access/SAPDB/Ingres/etc) is the only real database out there."
-
Alvin Submersible Retired After 40 Years Work
An anonymous reader writes "The legendary deep-sea manned submersible Alvin is retiring after 40 years of scientific work. Alvin has taken 12,000 people on over 4,000 dives, helping to confirm plate tectonics and continental drift. It discovered hydrothermal vents, salvaged a hydrogen bomb from the Mediterranean Sea and explored the Titanic. Alvin will be replaced by a larger vehicle that will come into service in 2008."
-
Samsung to use Sub-Pixel VGA Screens
pdawerks writes "Samsung Electronics has developed a new graphics chip that will allow half VGA screens to produce VGA resolution. The novelty is specially aimed at future mobiles with VGA screens that will be less than 2.4 inches. It generates color using an entirely new driving method called sub-pixel unit driving methodology." Not sure if I think it is exactly new or not, but it's nifty.
-
The Extinction of the Programming Species
Max Goff writes "Given the recent chatter surrounding the extinction of the U.S. programmer, /. readers might also be interested in a series of articles I recently penned for java.net -- the Blacksmith and the Bookkeeper (part 1, part 2 and part 3) -- in which I posit that the postmodern programmer (the entire sub-species, not just those domiciled in the U.S.) shares much with the blacksmith of old, and will become just as extinct in relatively short order. It is not due to work visas or outsourcing, but has much more to do with the evolution of work itself."
-
Can Coal Be Green?
wap writes "A coal-industry sponsored group, Americans for Balanced Energy Choices thinks coal is green, and has been running television ads to make its point. The ad shows an eagle unable to fly because of smog, and then talks about how much cleaner coal is now and will be in the future, with a sub-title saying that this is because of EPA regulation. Coal burning is much cleaner now than it was due to new scrubbing technologies, but it still emits just as much carbon dioxide as ever. Carbon emissions can be reduced by increased efficiency through gasification, but the only way to stop coal from emitting carbon dioxide is carbon sequestration. Everyone agrees that sequestration is expensive, but not everyone agrees that it's even effective in the long term. Should we instead follow the suggestion of James Lovelock and go nuclear as has been discussed here before?"
-
Debian Hardened Aims For Security
larryg writes "Debian Hardened is a new project that wants be an official Debian sub-project. It aims to provide a complete tree of hardened kernel and software packages for a standard Debian distribution, without changing to another like Adamantix and making easy the hardening of any machine running Debian GNU/Linux. The hardened kernels use the grSecurity patch and some of the Adamantix kernel patches; also, its packages are compiled with the ProPolice/SSP gcc extension and some libraries to prevent and trace buffer overflow attacks. Also, and as a second project, we are working on some enhacements against the Linux Entropy Pool engine, using an external TRNG (True Random Numbers Generator) device which uses thermal noise and also the atomic decay from a Geiger counter, making true unpredictable random numbers."
-
Romanian Team Entering X-Prize competition
cripkd writes "Although two days passed already I am proud to announce that a Romanian team launched a sub-orbital unmanned flight. Demonstrator 2 is a prototype to the actual shuttle they will enter in the X-Prize competition, build with 30,000 USD, pocket money, as they say, compared to the other projects. The project's home site is here and an article about the launch can be found here. PS. And it's all ecological as they produce oxygen and water vapours :)"