Question

When calling CoInitializeEx, you can specify the following values for dwCoInit:

typedef enum tagCOINIT {
    COINIT_MULTITHREADED     = 0x0,
    COINIT_APARTMENTTHREADED = 0x2,
    COINIT_DISABLE_OLE1DDE   = 0x4,
    COINIT_SPEED_OVER_MEMORY = 0x8,
} COINIT;

What does the suggestively titled "speed over memory" value do? Is it ignored these days in COM?

Was it helpful?

Solution

No idea if it's still used but it was meant to change the balance used by the COM algorithms.

If you had tons of memory and wanted speed at all costs, you would set that flag.

In low-memory environments, leaving that flag off would favor reduced memory usage.


As it turns out, the marvellous Raymond Chen (of "The Old New Thing" fame) has now weighed in on the subject and, despite what that flag was meant to do, it apparently does nothing at all.

See What does the COINIT_SPEED_OVER_MEMORY flag to CoInitializeEx do? for more details:

When should you enable this mode? It doesn't matter, because as far as I can tell, there is no code anywhere in COM that changes its behavior based on whether the process has been placed into this mode! It looks like the flag was added when DCOM was introduced, but it never got hooked up to anything. (Or whatever code that had been hooked up to it never shipped.)

Also http://archives.neohapsis.com/archives/microsoft/various/dcom/2001-q1/0160.html from Steve Swartz, one of the original COM+ architects:

COINIT_SPEED_OVER_MEMORY is ignored by COM.

OTHER TIPS

One of the flags you can pass to Co­Initialize­Ex is COINIT_SPEED_OVER_MEMORY, which is documented as: https://msdn.microsoft.com/en-us/library/ms678505(v=VS.85).aspx

COINIT_SPEED_OVER_MEMORY: Trade memory for speed. This documentation is already vague since it doesn't say which direction the trade is being made. Are you reducing memory to increase speed, or increasing memory by reducing speed? Actually it's neither: If you pass this flag, then you are instructing COM to consume more memory in an attempt to reduce CPU usage, under the assumption that you run faster by executing fewer cycles.¹

The request is a per-process one-way transition. Once anybody anywhere in the process puts COM into speed-over-memory mode, the flag stays set and remains set until the process exits.

When should you enable this mode? It doesn't matter, because as far as I can tell, there is no code anywhere in COM that changes its behavior based on whether the process has been placed into this mode! It looks like the flag was added when DCOM was introduced, but it never got hooked up to anything. (Or whatever code that had been hooked up to it never shipped.)

¹ As you know, consuming more memory is not a guarantee that you will actually run faster, because higher memory usage increases the chances that what you need will take an L1 cache miss or a page fault, which will cost you dearly in wait time (though not in CPU usage).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top