March 4, 2003

Using the Volatile Keyword to Avoid Failures

When compiling a program, the compiler adds some optimizations that may cause your application to misbehave. For example consider the following code: // To avoid threads waiting on the critical section in vainif (m_instance == NULL){EnterCiriticalSection(pcs);if (m_instance == NULL)m_instance = new MyInstance();} The compiler may cache the second condition (m_instance

Using the Const_cast Operator

The const_cast operator takes the form: const_cast (expr) It is used to add or remove the “const-ness” or “volatile-ness” from a type. Consider a function, f, which takes a non-const argument: double f( double& d ); Say you wish to call f from another function g: void g (const double&

How to Perform Geo-Location on BREW-based Phones

In this application, we will show you how you should be able to use the GPSOne features built into the BREW SDK to perform geo-location on BREW-based phones… once BREW phones featuring GPS hardware are commonly available on the market. We will combine this understanding with the powers of Microsoft’s

Select Case Enhancement

I have found the need to do multiple tests on dissimilar variables and objects with any failing test causing an action. Multiple embedded If…Then…ElseIf…EndIf statements are awful to look at and troubleshoot. I found that using Select Case does the trick and is easy to read. Consider testing several items

Sort Arrays Faster

When an array is declared as a type where each element occupies a lot of memory (such as a complex user-defined type), sorting the array can become unacceptably slow. To speed things up, the data contained within the array shouldn

Copy an Array Faster, Redux

Simple is usually best. VB4 introduced direct assignment to Byte arrays, and VB5 later expanded that capability to include other array types as well. This code does the same thing as the previous tip, with the same performance improvement: Dim IntArray1() As IntegerDim IntArray2() As IntegerReDim IntArray1(1 To 6000000)ReDim IntArray2(1

No more posts to show