c++

Are memory leaks ever ok?

Is it ever acceptable to have a memory leak in your C or C++ application? What if you allocate some memory and use it until the very last line of code in your application (for example, a global object's deconstructor)? As long as the memory consumption doesn't grow over time, is it OK to trust the OS to free your memory for you when you...

Which platform should I use : native C++ or C# ?

I want to develop a windows application. If I use native C++ and MFC for user interface then the application will be very fast and tiny. But using MFC is very complicated. Also If I use C# then the application will be slower than the native code and It reqiures .NET framework to run. But developing GUI is very easy by using WinForm. Whic...

If I use explicit constructor, do I need to put the keyword in both .h and .cpp files?

Actually my question is all in the title. Anyway: I have a class and I use explicit constructor: .h class MyClass { public: explicit MyClass(const string& s): query(s) {} private: string query; } Is it obligatory or not to put explicit keyword in implementation(.cpp) file? ...

What's an effective and somewhat easy to build system to allow customer to submit bug reports after deployment?

I'll be deploying a C++/DirectX/Windows game at the end of January to my customer and I'd like to setup an easy way for them to submit bug reports. Should I setup a website for this? Should I build it into the user interface of the game? Should I just have them send me an email? At a very high level, what are some ideas for an effect...

Singleton Destructors

Should Singleton objects that don't use instance/reference counters be considered memory leaks in C++? Without a counter that calls for explicit deletion of the singleton instance when the count is zero, how does the object get deleted? Is it cleaned up by the OS when the application is terminated? What if that Singleton had allocated...

Why Build Fails with CruiseControl.NET but it builds fine manually with same settings?

I have a project that builds fine If I build it manually but it fails with CC.NET. The error that shows up on CC.NET is basically related to an import that's failing because file was not found; one of the projects (C++ dll) tries to import a dll built by another project. Dll should be in the right place since there's a dependency betwee...

Performance implications of &p[0] vs. p.get() in boost::scoped_array

The topic generically says it all. Basically in a situation like this: boost::scoped_array<int> p(new int[10]); Is there any appreciable difference in performance between doing: &p[0] and p.get()? I ask because I prefer the first one, it has a more natural pointer like syntax. In fact, it makes it so you could replace p with a native...

c++ integer->std::string conversion. Simple function?

Problem: I have an integer; this integer needs to be converted to a stl::string type. In the past, I've used stringstream to do a conversion, and that's just kind of cumbersome. I know the C way is to do a sprintf, but I'd much rather do a C++ method that is typesafe(er). Is there a better way to do this? Here is the stringstream ap...

Search entire project for includes in Eclipse CDT

I have a large existing c++ codebase. Typically the users of the codebase edit the source with gvim, but we'd like to start using the nifty IDE features in Eclipse. The codebase has an extensive directory hierarchy, but the source files use include directives without paths due to some voodoo we use in our build process. When I link th...

Intercepting traffic to memcached for statistics/analysis

I want to setup a statistics monitoring platform to watch a specific service, but I'm not quiet sure how to go about it. Processing the intercepted data isn't my concern, just how to go about it. One idea was to setup a proxy between the client application and the service so that all TCP traffic went first to my proxy, the proxy would ...

Parallel quicksort: recursion using Boost Bind?

I am working on making quicksort parallel, threads being the first attempt. The non threaded version sorts correctly but the threaded doesn't (no surprise there). What I found interesting was when I removed the threads but kept the boost::bind calls it still doesn't work. If boost::bind isn't what I want please offer a suggestion. Bi...

How can I debug a MinGW EXE with the Microsoft Visual C++ debugger?

How can I debug a MinGW EXE with the Microsoft Visual C++ debugger? ...

What is the slicing problem in C++?

Someone mentioned it in the IRC, but google doesn't have a good answer. ...

How can I correctly downcast the pointer from void* to TMemo* in C++Builder2009?

Hello, I am writing multi-thread socket chat in C++Builder 2009. It is almost complete in accordance with what I need to do but I have a little problem. I need to pass the TMemo* pointer into CreateThread WinAPI function which upcasts it to void*. I tryed this way: HANDLE xxx = MemoChat->Handle; hNetThread = CreateThread(NULL, 0, NetTh...

How do I calculate the week number given a date?

If I have a date, how do I calculate the week number for that date within that year? For example, in 2008, January 1st to January 6th are in week 1 and January 7th to the 13th are in week 2, so if my date was January 10th 2008, my week number would be 2. An algorithm would be great to get me started and sample code would also help - I'...

What is the best way to call C/C++ code from other languages such as Java, PHP, Perl, Python, etc?

What is the best way to call C/C++ from other languages such as Java, Python, Perl, PHP, etc? ...

Chaining of ordering predicates (e.g. for std::sort)

You can pass a function pointer, function object (or boost lambda) to std::sort to define a strict weak ordering of the elements of the container you want sorted. However, sometimes (enough that I've hit this several times), you want to be able to chain "primitive" comparisons. A trivial example would be if you were sorting a collectio...

C++ Timer function to provide time in nano seconds

I wish to calculate the time it took for an API to return a value. The time taken for such an action is in the space of nano seconds. As the API is a C++ class/function, I am using the timer.h to caculate the same: #include <ctime> #include <cstdio> using namespace std; int main(int argc, char** argv) { clock_t start; dou...

Parallel assignment in C++

Is there any way of doing parallel assignment in C++? Currently, the below compiles (with warnings) #include <iostream> int main() { int a = 4; int b = 5; a, b = b, a; std::cout << "a: " << a << endl << "b: " << b << endl; return 0; } and prints: a: 4 b: 5 What I'd like it to print ... if it weren't obviou...

what is "operator T*(void)" and when it is invoked?

I have 2 files: /****demo.cpp****/ #include <iostream.h> #include "gc.h" class foo{}; int main(){ gc<foo> x1; cout<<x1; } /*****gc.h*****/ template <class T> class gc { T* ptr; public: operator T*(){} }; If I don't write operator T*(){} then I get a lot of compiler errors. So plz tell me what is operator T*(void) ...