c++

memory leak unit test c++

I have just resolved a memory leak in my application and now I want to write a unit test to ensure that this does not happen again. I'm look for a way to detect the memory usage of the current application (working set), before and after some functions. For example: long mem_used= GetMemUsed(); /* Do some work */ /* clean up */ if...

How to bound 2 variables in C++ one with other so when one changes changes another?

How to bound 2 variables in C++ one with other so when one changes changes another? for example I created Int A and Int B bound one to another and than when I change A one using some function another one will automatically change to new value of A. I am intrested in version for C++ .net 4th version. ...

Understanding CComBSTR assignment operators

Say I have the following: BSTR myBSTR = SysAllocString( L"MYBSTR" ); CComBSTR myCComBSTR = myBSTR; Does myCComBSTR take ownership of myBSTR and free it when it goes out of scope? Or does it make a copy of myBSTR and produce a memory leak if i dont free myBSTR? If this produces a memory leak, what's the most efficient way of handling ...

C++ cursor changes to hour glass using WM_SETCURSOR

OK i have a game when person loses ill set a different cursor. i used the setcursro with loadcusor and WM_SETCURSOR. the problem is that my default cursor which i hae set it where i register my window, it changes to hour glass until the person loses than it changes to the cursor i have set it to. i found that when i use the WM_SETCURSOR ...

efficient algorithm for searching one of several strings in a text?

I need to search incoming not-very-long pieces of text for occurrences of given strings. The strings are constant for the whole session and are not many (~10). Additional simplification is that none of the strings is contained in any other. I am currently using boost regex matching with str1 | str2 | .... The performance of this task is...

QList acting strange

Hi! I don't have much experience with Qt but somehow I think this is acting strange. Compiled with VS2005: class Entry { public: Entry(const QString& aName, bool checked) : name(aName), isChecked(checked) { // empty }; public: Entry(const Entry& entry) : name(entry.name), isChecked(entry...

c++ set cursor size over 32

im trying to set a cursor. the width and the height of the cursor is bigger than 32 px. but it just scale it down to 32px when i set it. any idea? ...

Why does this virtual destructor trigger an unresolved external?

Consider the following: In X.h: class X { X(); virtual ~X(); }; X.cpp: #include "X.h" X::X() {} Try to build this (I'm using a .dll target to avoid an error on the missing main, and I'm using Visual Studio 2010): Error 1 error LNK2001: unresolved external symbol "private: virtual __thiscall X::~X(void)" (??1X@@EAE@XZ...

In C++, why isn't the this keyword a reference?

Possible Duplicate: Why this is a pointer and not a reference? Hey guys, Is there a good reason that this is a pointer instead of a reference in C++? ...

Using Cairo on iPhone?

I'm doing some work on a potentially cross-platform C++ application and for Windows and OS X it seems that Cairo will meet most of my needs for 2D graphics and allow me to share a lot of code between platforms. In an ideal world I'd really like to be able to use the same (or very similar) drawing code in iPhone/iPad apps. I realise tha...

How to use/install custom Directshow filter

Hi I have custom compiled directshow filter - filter.DLL - but how to use, or install this filter in system? Amanda ...

What's the simplest way to write portable dynamically loadable libraries in C++?

I'm working on a project which has multiple similar code paths which I'd like to separate from the main project into plugins. The project must remain cross-platform compatible, and all of the dynamic library loading APIs I've looked into are platform specific. What's the simplest way to create a dynamic library loading system which can ...

A very simple thread pool using pthreads in C++

Hello, I'm trying to understand some of the basics of using POSIX pthreads. The kind of thing I need to do (eventually) is parallelize some computations, using a thread pool model. At present I want to ensure I have a very basic sense for how the POSIX pthread model works. So I'm trying to create the simplest thread pool that's gen...

C++ what does >> do

What does >> do in this situation? int n = 500; unsigned int max = n>>4; cout << max; It prints out 31. What did it do to 500 to get it to 31? ...

Where can I start with programmable Hardware?

I've had a desire to learn at least a tiny bit about programming hardware for quite some time now and thought I'd ask here to get some starting points. I am a reasonably accomplished programmer with Delphi and Objective-c experience but have never even listened to a device port / interupt (I dont even know the terminology) let alone pro...

i want a variable that will change from a char to a int and vice versa depending on the user entry

i have to define a variable that i am using in a program but i want the variable to change from int to char. example #include <iostream> #include <cstdlib> int main() { int l=rand(); char x; std::cout<<"this program makes a random char or number enter n for a number or c if you want a letter\n"; std::cin>>l>>"\n"; ...

Memory comparison (with difference position)

Hello! Is there a way to compare two blocks of memory, and know at which point they differ (memcmp() does not meet this requirement)? I wouldn't want to perform costly loops. Thanks in advance. Regards, Neo_b ...

Will C++ throw with no arguments work inside another frame to rethrow an exception?

If I have a code like the following: try { doSomething(); } catch (...) { noteError(); } void noteError() { try { throw; } catch (std::exception &err) { std::cerr << "Note known error here: " << err.what(); } catch (...) { std::cerr << "Note unknown error here."; } throw; } Will the original exceptions get t...

c++ using too much cpu

ok im creating a game but it uses too much cpu but it doesn't uses too much memory. the cpu does increase and decrease. i have too many timers in my game, i kill the timer when i don't use it any more so that should cause a problem but what i think that causes the problem is there is too many messages in my message qeue. i have new lapt...

Why does C++ not allow inherited friendship?

Why is friendship not at least optionally inheritable in C++? I understand transitivity and reflexivity being forbidden for obvious reasons (I say this only to head off simple FAQ quote answers), but the lack of something along the lines of virtual friend class Foo; puzzles me. Does anyone know the historical background behind this dec...