Happy tickets benchmark

Some countries have integer numbers printed on the transport tickets, for example, in ex-USSR. The ticket is "happy" when the sum of the first half of digits equals to the second one. Then you should eat it and make a wish.

Example:

123456 and 111222 are not happy tickets
123123 and 123222 are the happy tickets

Bit-packed structure (record) in Free Pascal and Delphi

Here is the code explaining some methods to pack bit accessing logic in your program.

program project1;
 
type
  TRec1 = packed record // Doesn't pack at all
    b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16: boolean;
  end;
 
  TRec2 = bitpacked record // Free Pascal specific
    b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16: boolean;
  end;
 
  TRecByte = (b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16);
  TRecBytes = set of TRecByte;
var
  r1: TRec1;
  r2: TRec2;
  s1: TRecBytes;

Windows XP multiprocessor/core support

How to add support of multi-core/multiprocessor support to Windows XP SP3?

Run this in command line:

rundll32 syssetup,SetupInfObjectInstallAction ACPIAPIC_MP_HAL 128 %windir%\inf\hal.inf

This command replace single-core kernel to multi-core kernel without reinstalling Windows. You should be required to confirm driver installation and to reboot twice.

Sorted map vs hashed map

In theory, hash map structure should be very fast on retrieving by key operations, close to O(1) like for an array. A sorted map (keys are sorted) should be O(log2 N) instead. The following test checks the difference.

Common scenario

We will use one tester class per type of tested structure. The keys are string[10] and are generated randomly in prepared array to avoid additional checks whether the key exists or not.

Interface implementations and multiple inheritance in C++

Multiple inheritance of interfaces which are pure abstract classes indeed is not a problem until you need to use the interface implementation in other classes.

Suppose there are two interfaces, the implementation of which will be used in other classes.

Pages

Subscribe to Mechanics of software RSS