Skip to main content

Posts

Showing posts from June, 2009

What is placement new?

It's a way to pass parameters to the allocator rather than just to the constructor. Allocating an object from the heap, such as new Fred(5,7), is a two-step process: first an appropriately sized and aligned block of uninitialized memory is allocated from the heap, then the constructor is called with the this pointer pointing to that block of memory. Parameters are often passed to the constructor (for example, the above example passes (5,7)), but occasionally parameters also must be passed to the allocation step. For example, if there was a special allocator that used a particular pool of memory, it might be necessary to pass a reference to that pool of memory to the allocation step, that is, to new itself: new(myPool) Fred(5,7). Another common reason to pass a parameter for the allocation step is to pass a pointer to a particular preallocated region of memory. For example, if pointer p is a void* that points to a pile of memory that is at least sizeof(Fred) bytes long and is approp

What is the Standard Template Library?

A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.

What is a mutable member?

One that can be modified by the class even when the object of the class or the member function doing the modification is const. Understanding this requirement implies an understanding of C++ const, which many programmers do not have. I have seen large class designs that do not employ the const qualifier anywhere. Some of those designs are my own early C++ efforts. One author suggests that some programmers find const to be such a bother that it is easier to ignore const than to try to use it meaningfully. No wonder many programmers don't understand the power and implications of const. Someone who claims to have enough interest in the language and its evolution to keep pace with the ANSI deliberations should not be ignorant of const, however.

Why is STL Container list<>::size() linear time?

The size() member function, for list and slist, takes time proportional to the number of elements in the list. This was a deliberate tradeoff. The only way to get a constant-time size() for linked lists would be to maintain an extra member variable containing the list's size. This would require taking extra time to update that variable (it would make splice() a linear time operation, for example), and it would also make the list larger. Many list algorithms don't require that extra word (algorithms that do require it might do better with vectors than with lists), and, when it is necessary to maintain an explicit size count, it's something that users can do themselves. This choice is permitted by the C++ standard. The standard says that size() "should" be constant time, and "should" does not mean the same thing as "shall". This is the officially recommended ISO wording for saying that an implementation is supposed to do something unless there is

What types of threads are supported by MFC ? How they can be created ?what is the difference between them?

1. Worker Threads. Provide only background processing. Doesn't handle messages. Creation: By calling AfxBeginThread() and providing a global function as a parameter. 2 UI Threads. These threads have the UI (Window) and can process the messages, i.e. user interaction (I/O) with window. Creation: By calling AfxBeginThread() and providing a class which is derived from CWinThread and implements all message handling mechanism as a parameter.

What is a DLL or Dynamic Link Library?

Microsoft has provided a way of linking a library dynamically. Under Windows terminology, such a library is referred to as Dynamic Link Library (DLL) . A DLL is an executable file that gets loaded when an application that uses the DLL gets executed. DLLs can reduce memory and disk space requirements by sharing a single copy of common code and resources among multiple applications. When more than one application uses the same DLL, the operating system is smart enough to share the DLL’s read-only executable code among all the applications. DLLs are compiled and linked independently of the applications that use them; they can be updated without requiring applications to be recompiled or relinked. If several applications work together as a system and they all share such common DLLs, the entire system can be improved by replacing the common DLLs with enhanced versions. A bug fix in one such DLL indirectly fixes the bug in all applications that use it. Likewise, performance enh