c++

What happens when windows encounters an unknown instruction in a binary?

We have a binary compiled with SSE3 optimizations which end up using the instruction LDDQU. Now when this code is executed on a Windows system (Single core, XP2) which has only SSE1,2 support (as seen through CPU-Z tool) then application crashes. (924.4f0): Invalid lock sequence - code c000001e (first chance) ... 001700a10 f20ff00430 ...

Why should I check the return value of operator NEW?

hello everyone, Meyers in his book "50 ways to improve..." second edition writes that I must check return type of new, but I know that if operator NEW can't allocate memory it throws exception, so with newer libraries I don't need to check return value of new, am I right? thanks in advance ...

Write a program to count how many times each distinct word appears in its input. Use C++.

This is a question(3-3) in ACCELERATED C++. I am a fresh man for C++. I have thought for a long time, however, failed figuring it out. Will anyone kind to resolve this problem for me? Thank you very much. Please explain it in detail, you know I am not very good at programming. Tell me the meaning of the variables you use. THANKS A LOT! ...

Injecting code in a C++ base class constructor

I'm deriving a class which is available from a C++ library, and the constructor of my subclass will only work properly when I execute some code before the base class constructor gets called. (Yes, I know, bad design, but I cannot influence how the library which I'm using works.) If the base class constructor takes arguments, doing this ...

Any native XML DOM on Windows with control over memory allocation?

I'm looking to replace MSXML with a library that will allow us to use DOM processing but using our own allocation, so we can assure it is mapped directly onto a memory-mapped file. This avoids having to synch the DOM back to the file. Can anyone please suggest which of the various libraries out there is most likely to be easily customise...

Expert in one language or know more languages

In the corporate world, Is it better to be knowledgeable(by knowledgeable I mean not a expert or novice but with some coding experience) about multiple languages. or is it better to be an expert in one language(say c++ or java) but having just basic knowledge on others. I ask this question because what I feel is languages can be dif...

Get underlying window's color

I have a color-transparent window. I need to change its color to contrast with the underlying screen area (be it a window or the desktop). So how does one detect the underlying color? C/C++ ...

Windows tcmalloc replacement with static linking

A C++ project encounter the memory fragmentation problem, and tried following: nedmalloc- Did not pass the stress test (crashed after 15 hrs), that means it works in the most of cases but not the all. And more memory usage than other allocators. jemalloc- Not ready for Windows? tcmalloc- Compiled with host code with static linking, bu...

Try to write char[] to a text file

I trying to write a char[256] to a text file. Below is my current work: fstream ofs; ofs.open("c:\\myURL.txt"); ofs.write((char*)testDest,256); ofs.close(); It still does not work. here is the error: error C2440: 'type cast' : cannot convert from '' to 'char *' update: so far, here is my progre...

How to create a COM DLL (class library)?

I have an existing COM DLL (class library), originally written in VB6 and source code now lost. I need to very quickly rewrite to make a minor tweak it and don't have access to VB6. I understand that C++ Express 2008 will let me create the DLL, but I get bogged down ATL and the like. Is there a really simple step by step guide to creat...

Default class inheritance access

Suppose I have a base and derived class: class Base { public: virtual void Do(); } class Derived:Base { public: virtual void Do(); } int main() { Derived sth; sth.Do(); // calls Derived::Do OK sth.Base::Do(); // ERROR; not calls Based::Do } as seen I wish to access Base::Do through Derived. I get a compi...

What is the difference between sizeof(int) and sizeof(int*)? Also Is this statement int* numbers[] = {....} correct?

Suppose, int numbers [20]; int * p; I think this is statement is valid p = numbers; But this is not numbers = p; Because numbers is an array, operates as a constant pointer, and we cannot assign values to constants. So if we go by this then we cannot use *numbers while initializing the array? ...

Can I call cuda function calls in C++?

Is there any way I can call cuda function calls such as cudaMemcpy(...); in a .cpp file, or call it in a class method? ...

Restricting template instantiation using is_integral / BOOST_STATIC_ASSERT

I am trying to implement a free operator function in order to stream values of arbitrary data type into some container class (DataVector). I did a template for basic data types and some specializations for the complex data types used in my project (examples covers std::string only). To make sure the template won't be used with a data typ...

Can't build sigqueue example with gcc but g++ is ok?

Hi I have a strange build problem. I have a simple test program that sends a sigqueue to another process. This little code example builds and runs when I build it as a c++ program (compiled with g++) but when I compile it as a c program (with gcc) I get a error that he can't find the sigval struct. The short example: #include <std...

Program won't run with really big numbers

Hi there, I'm pretty new to programming and so I"m making this program in C++ that will take a number and find it's prime factors, which works great! Unless it's too big for an int variable. Now then I tried to change all of the int variables to long long variables so it wouldn't matter, but this doesn't seem to fix the problem. The prog...

Is there a standard Cyclic Integer Class in C++?

I have a problem that is quite common in the code that I am writing at the moment whereby I want to have an integer that can only exist inside a certain range where the range is [start, end). Basically I want to be able to do something like the following: cyclic_int ci(4, 8); ci = 4; assert(ci == 4); ci += 3; assert(ci == 7); ci += 2; ...

freeing memory issue

Hi All, I have an issue regarding freeing memory as under: string points; // some points sequences char* charPoints = (char*)malloc((points.length() +1) * sizeof(char)); //do something free(charPoints); Even then after freeing memory is leaked when checked with instruments ...

screenshots sequence to compressed video

hi, I'm trying to accomplish relativly simple task: capture screenshot every N sec to bitmaps array in memmory encode bitmaps video to Windows Media Video 9 Screen Encoder format , and put it in another place in memory by now i did the first part , but second is little trickier. i did this: initialize COM for DMO with CoInitia...

Lightest synchronization primitive for worker thread queue

I am about to implement a worker thread with work item queuing, and while I was thinking about the problem, I wanted to know if I'm doing the best thing. The thread in question will have to have some thread local data (preinitialized at construction) and will loop on work items until some condition will be met. pseudocode: volatile bo...