c++

App Verifier reporting "Thread cannot own a critical section."

So App Verifier is throwing this exception. From what I gather, the text of this message is a little misleading. The problem appears to be that the the critical section was created by a thread that is being destroyed before the critical section is destroyed. It's a relatively simple fix but does anyone know what the ramifications ar...

Asynchronous screen update to gameplay logic, C++

Hello. I am programming a game using Visual C++ 2008 Express and the Ogre3D sdk. My core gameplay logic is designed to run at 100 times/second. For simplicity, I'll say it's a method called 'gamelogic()'. It is not time-based, which means if I want to "advance" game time by 1 second, I have to call 'gamelogic()' 100 times. 'gamelogic()'...

A reasonable approach to class size reduction using templates?

Given: (Code reduced to a sensible minimum) // MemberTypes template < typename SPEEDTYPE = float, typename SIZETYPE = float, typename ACCELERATIONTYPE = float > struct ParticleMemberTypes { typedef typename SPEEDTYPE SpeedType; typedef typename SIZETYPE SizeType; typedef typename ACCELERATIONTYPE AccelerationType; }; // ...

Memory Bandwidth Usage

How do you calculate memory(RAM) bandwidth used? Which performance counters are required? I came across a tool that was able to do it, the "Rightmark multi-threaded memory test". But unlike the rest of Rightmark's tests, I haven't found the source code for it, just the binaries. Thanks in Advance Tom De Bie ...

How to resolve Link error 2005 in visualstudio??

error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits @D@std@@@1@_N@Z) already defined ...

Return a multidimensional array from pointer function in Visual C++

Hello, I wrote following code to return multidimensional array from pointer function.Input parameter of this function is one dimensional array, output is pointer that point multidimensional array. double **function( array< double>^ data,int width,int height ) {int i; //define returning variable that point multidimensional arr...

How to use preprocessor to compute and store hashes at compile time?

I have a native C++ program that uses "event queues" to execute functions on different threads. I allocate an "event" class on the heap, and put it on one of my threads' queues for execution. It all works great, but it's very difficult to trace back the origin of these "events". I would like each "event" to store some information pertai...

How to speed up c++ linking time

Hi, Is there any way, to optimalize linking time in MS Visual studio C++ (2005) ? We're using Xoreax Incredibuild for compilation speed up, but nothing for link. Currently every linking takes about 30seconds. When I turn on incremental linking, takes abou 35-40 seconds. ( No matter if i compile project with or without incredibuild ) ...

What's the point of this pattern: using a struct to contain a single method

In our code we have quite a few cases of this pattern: class outerClass { struct innerStruct { wstring operator()( wstring value ) { //do something return value; } }; void doThing() { wstring initialValue; wstring finalValue = innerStruct()( initialValu...

how to check if a directory is writeable in win32 C/winapi?

I know of two methods which are not reliable: _access() - doesn't work on directories (only checks existence) CreateFile() - gives false positives in the presence of virtual store (AFAIK) Most useful would be a code sample, because the win32 ACL access functions are extremely complicated. Please don't post links to msdn, I've been th...

Managed CPP reference paths?

I'm trying to compile a managed cpp application from the command line. Suppose my cpp application references the .NET 2.5 framework's "System.dll". I can compile like this, without problems: cl /clr /FU"System.dll" main.cpp The application then works as expected. If, however, I try to reference the .NET 3.5 framework's "System.core...

Image Arithmetic functions in C++

I'm trying to find/write a function that would perform the same operation as imlincomb(). However, I am having trouble finding such functions in C++ without using any Matlab API functions other than Intel Performance Primitiives library, and I don't really want to purchase a license for it unless my application really has to take advanta...

GetOpenFileName() does not refresh when changing filter

I use GetOpenFilename() to let the user select a file. Here is the code: wchar_t buffer[MAX_PATH] = { 0 }; OPENFILENAMEW open_filename = { sizeof (OPENFILENAMEW) }; open_filename.hwndOwner = handle_; open_filename.lpstrFilter = L"Video Files\0*.avi;*.mpg;*.wmv;*.asf\0" L"All Files\0*.*\0"; ope...

Is there any real risk to deriving from the C++ STL containers?

The claim that it is a mistake ever to use a standard C++ container as a base class surprises me. If it is no abuse of the language to declare ... // Example A typedef std::vector<double> Rates; typedef std::vector<double> Charges; ... then what, exactly, is the hazard in declaring ... // Example B class Rates : public std::vector<...

C++ Array Shuffle

I'm fairly new to C++ and don't quite understand function parameters with pointers and references. I have an array of Cards that I want to shuffle using the Fisher-Yates shuffle. The deck is declared as Card *deck[deckSize]; where deckSize has been declared as 24. The array is then initialized. I then call the shuffle function: v...

Consistent pseudo-random numbers across platforms

Hello, I am looking for a way to generate pseudo random number sequences that will yield identical sequence results for a given seed across any platform. I am assuming that rand()/srand() is not going to be consistent (I could easily be wrong about this assumption). ...

Why can't I make a vector of references?

When I do this: std::vector<int> hello; Everything works great. However, when I make it a vector instead: std::vector<int &> hello; I get horrible errors like "error C2528: 'pointer' : pointer to reference is illegal". I want to put a bunch of references to structs into a vector, so that I don't have to meddle with pointers. Why i...

Removing map element by value

I'll keep this brief. I am trying to keep a map between strings and object pointers, and as such, I use std::map. I have a manager that's a global class that keeps track of the map, and whenever an object's destructor is called, it tells the manager that it has been deleted. The only way I can think of is to search through the map for ...

Unique class type Id that is safe and holds across library boundaries

I would appreciate any help as C++ is not my primary language. I have a template class that is derived in multiple libraries. I am trying to figure out a way to uniquely assign an id int to each derived class. I need to be able to do it from a static method though, ie. template < class DERIVED > class Foo { public: static int s_id...

How to allow template function to have friend(-like) access?

How does one modify the following code to allow template function ask_runUI() to use s_EOF without making s_EOF public? #include <string> #include <iostream> #include <sstream> #include <vector> class AskBase { protected: std::string m_prompt; std::string m_answer; virtual bool validate(std::string a_response) = 0; public: ...