c++

C++ iterators & loop optimization

I see a lot of c++ code that looks like this: for( const_iterator it = list.begin(), const_iterator ite = list.end(); it != ite; ++it) As opposed to the more concise version: for( const_iterator it = list.begin(); it != list.end(); ++it) Will there be any difference in speed between these two conventions? Naively the...

Threaded implementation of observer pattern - C++

I'm developing a C++ program which has a "scan" method which will trigger a relatively long running scanning procedure. When the procedure is completed, the scan method will notify observers of results using the observer pattern. I would like to create a separate thread for each scan. This way I can run multiple scans simultaneously. W...

C++ new operator thread safety in linux and gcc 4

Soon i'll start working on a parallel version of a mesh refinement algorithm using shared memory. A professor at the university pointed out that we have to be very careful about thread safety because neither the compiler nor the stl is thread aware. I searched for this question and the answer depended on the compiler (some try to be so...

Replacing getpid with my own implementation

I have an application where I need to write a new getpid function to replace the original one of the OS. The implementation would be similar to: pid_t getpid(void) { if (gi_PID != -1) { return gi_PID; } else { // OS level getpid() function } } How can I call the original getpid() implementation of the...

g++ compiler flags - Optimization and flags for making a static library - C++

I am just starting with g++ compiler on LINUX and got some questions on the compiler flags. Here are they Optimizations I read about optimization flags -O1,-O2 and -O3 in the g++ manual page. I didn't understood when to use these flags. Usually what optimization level do you use? g++ manual says the following for -O2. Optimize even...

Are memory mapped files bad for constantly changing data?

I have a service that is responsible for collecting a constantly updating stream of data off the network. The intent is that the entire data set must be available for use (read only) at any time. This means that the newest data message that arrives to the oldest should be accessible to client code. The current plan is to use a memory ma...

How to create a boost thread with data?

I'm running into some issues with boost::bind and creating threads. Essentially, I would like to call a "scan" function on a "Scanner" object, using bind. Something like this: Scanner scanner; int id_to_scan = 1; boost::thread thr1(boost::bind(&scanner::scan)); However, I'm getting tripped up on syntax. How do I pass the ...

When to use boost thread join function?

I've recently managed to create a thread using the boost::bind function. For the time being, I'm having the thread display to stdout. I can see the output if I use thread.join. However, if I don't do this, I don't see any output. Why is this? I'm hoping I don't have to use the join function, because I would like to call this functi...

Strange C++ std::string behavior... How can I fix this?

Hi All! This is driving me nuts. I have been at it for over 2 hours trying to figure this out... Here is my problem. I am working on a fairly large program that works with Bayesian networks. Here is the main function: using namespace std; int main() { DSL_network net; initializeNetwork(net); setEvidence(net); ne...

Fast Cross-Platform C/C++ Image Processing Libraries

What are some cross platform and high performance image libraries for image processing (resizing and finding the color/hue histograms). No gui needed. This is for C/C++. So far I have looked in to OpenCV GIL as part of Boost DevIL CImg My questions How's the performance of the ones I have listed above What are some other librari...

Are there known false positives issues with Valgrind?

Hello, Are there any known false positives with Valgrind? (myself I get a 'Conditional jump or move depends on uninitialised value(s)' with the 'fmemopen' function, writing in 'c' and gcc, can I be sure it's real?) EDIT: are there known issues that are not in the suppression files? Are there some things one can do in a program, that ...

How to integrate/mix managed and unmanaged code

Hi there is project already devoloped using unmanaged code. now in a small module to use SQLSMO in C++ i hav used managed code.Now the problem is how to integrate manged code with unmaged code... can any body help me in this regard with small exampe... if u do this u help me a lot Thanks in advance.... ...

JNI vs. C++ Object Instances

I have just started at a new job. Here we are new to using JNI ( for bridging C++ / Java ). I am new to JNI so please forgive my noobness :) In our (win32) Java app we are loading a C++ DLL. On the Java side we have several instances of "SomeJClass" each of these instances needs access to corresponding instance of "SomeCClass" on the DL...

Can I stop std::cout flushing on "\n"?

Hi, According to to this post std::cout will automatically flush on \n when it is attached to an interactive device (e.g. a terminal window). Otherwise (e.g. when being piped to a file) it will act fully buffered and will only flush on .flush() or std::endl. Is there a way to override this behaviour in Microsoft Visual C++ so that I ca...

VC++ Charts using Chart X

Hi, I'm new to drawing the chart using chartfx can you give me the meanings of teh following methods, they are kinda confusing...I did not find documentation anywhere. GetValue ( ) GetXValue ( ) PutItem() Thanks, Arjun ...

How do I declare an array of strings in C++?

In C++ how can I declare an array of strings? I tried to declare it as an array of char but that was not correct. ...

Qt4 existing slots are not recognized.

Hi I am currently trying to complete a project using Qt4 and C++. I am using buttons to switch between states. While trying to connect the buttons' clicked() signals to the textEdit to display the relevant state, I got stuck on an error: Object::connect No such slot QTextEdit::append("move state") Object::connect No such slot ...

Resources for C++ Templates

I'm new to C++ Templates, and am finding it hard to understand and debug them. What are some good resources for doing both/either? ...

C++ -- Strange output after reading from a file

Using this code, the following execution yields strange results: C 100 R W The text file's first line defines the number of elements to read from it, and it contains a few values under 15, but every time I run this, the first value in my array is always printed out as 87 (the ASCII value for 'W'). If I change the 'W' functionality to '...

When a compiler can infer a template parameter?

Sometimes it works sometimes not: template <class T> void f(T t) {} template <class T> class MyClass { public: MyClass(T t) {} }; void test () { f<int>(5); MyClass<int> mc(5); f(5); MyClass mc(5); // this doesn't work } Is there a way to hack around the example above? I.e. force the compiler to infer the template paramete...