May 5, 2000

Generate Audit Table Trigger Code

This code will generate code to do a column-by-column comparison against a table, assuming that you are joining the inserted table (aliased as “i”) with the deleted table (aliased as “d”) in a trigger: SET NOCOUNT ONDECLARE @x sysnameSELECT @x = ‘authors’CREATE TABLE #x(SQL varchar(255), colid int )INSERT #xselect ‘OR

Models of Garbage Collectors

If you need a garbage collector, you can either install one or implement it by yourself. Which type of garbage collection should you use? A conservative garbage collector and a copying garbage collector are the two most common models. A conservative garbage collector doesn’t move objects from one place to

Preventing Memory Fragmentation

Applications that are free from memory leaks but perform dynamic memory allocation and deallocation frequently tend to show gradual performance degradation if they are kept running for long periods. Finally, they crash. Why is this? Recurrent allocation and deallocation of dynamic memory causes the heap to become fragmented, especially if

Default Arguments in a Template Instantiation

Templates can have default type parameters. The compiler uses these default types when you don’t provide them explicitly in a template instantiation. For example: template < class T1=char, class T2=char > // default typesclass E { public: E( T1 t1, T2 t2 ) {m1=t1; m2=t2; } private: T1 m1; T2

Avoid Hardcoded Literal Strings

Hardcoded literal strings can become a serious maintenance problem. Suppose you have numerous message boxes in your application that display a hardcoded text message and you want to change that message. You have to chase every occurrence of the message box in your source file. A similar problem will arise

Multiple Drawing Threads

Question: I have written an applet which uses a Graphics object to draw movingcircles. However, when multiple threads accesses the same Graphics object,the circles disappear after being on screen for around 5 seconds,without throwing an exception. Why does this happen and how do I curethis? Answer: AWT graphics are designed

A HashMap of HashMaps

Question: I have been looking everywhere for information on HashMaps,particularly how to put one hash map into another HashMap. Answer: This is where the expression RTFM (Read That Fine Manual) comes tomind. Although notorious for being extremely sparse in certainsections, the javadoc API documentation that comes with the Java 2Platform

Determining Stack Content Type

Question: Only Objects can be popped from, or push onto, a stack. That means Ihave to wrap a primitive data type, such as int, with something akin toInteger before pushing it onto a stack. How can I identify the typeof an object popped from a stack? Answer: Ideally, when you

Synchronization Between File Writes and Reads

Question: How do I determine if a Unix process has stopped writing to a file,so that my Java program can start reading it? Answer: If you are not able to modify the source code for the Unix program,you may well be out of luck. If you can modify the source

No more posts to show