July 3, 2001

Differences Between Initialization Forms

Suppose you have an aggregate, i.e., a struct or a union that contain another struct as a member: struct A{ int x; int y;};union B{ A var1; float var2;}; Can you tell the difference between the following initialization forms? B arr[3] = {1,1,1}; B arr[3] = {{1},{1},{1}}; The first statement

Class Template auto_ptr and Arrays

The std::auto_ptr class template handles only a pointer to a single object. This is because it uses scalar delete, never delete[], to destroy the owned object. Therefore, binding auto_ptr to an array of objects would cause undefined behavior. Using of auto_ptr as a char pointer is a common mistake: std::auto_ptr<

The std::pointer_to_unary_function Template

The Standard Library defines several template adaptors for function pointers. The std::pointer_to_unary_function class template encapsulates a pointer to a single argument function. std::pointer_to_unary_function overloads the () operators so that you can use an instance of this template as a function. In the following example, this template serves as a wrapper

Initializing a Static Array Member of a Class

You can initialize static arrays member of a class. The initialization must appear at the place of definition, not inside the class body. For example: class A{private: static char vars[2]; // declaration, can’t initialize here//..};char A::vars[2] = {‘a’, ‘b’}; // definition + initialization

The ## Concatenation Operator

The preprocessor ## operator concatenates macro arguments. For example: #define paste(x,y) x ## y The paste() macro takes two arguments and concatenates them into one. The whitespaces surrounding the ## operator as well as the ## symbol are removed in the concatenation process. In the following example, the paste() function-like

Avoid Heap Fragmentation in Palm OS

Memory is precious in Palm OS, since the total amount of memory available is very small. Dynamic memory allocation is often necessary while building applications in which memory at runtime is required. One should always allocate dynamic memory using handles rather than pointers. Palm OS can move handle based memory

Nested Transactions

You can use the @@TRANCOUNT function to determine whether any open transactions exist and how deeply they are nested.A BEGIN TRANSACTION statement increments @@TRANCOUNT by one, and a ROLLBACK statement sets @@TRANCOUNT to zero.

Manipulating Text Field Data in a SQL Stored Procedure

The code below is functionally equivalent to a VB Replace function, but, instead, it allows you to perform an action in a Text type field in a SQL Server Stored Procedure. This functionality can be especially useful in content management type situations, allowing you, for example, to replace all carriage

Lock Timeout!

With the SET LOCK_TIMEOUT option, it is possible to set the maximum amount of time that SQL Server allows a transaction to wait for the release of a blocked resource: Syntax SET LOCK_TIMEOUT timeout_period ‘timeout_period’ indicates the number of milliseconds, while a value of -1 (the default) indicates no timeout

No more posts to show