c++

Network Multithreading

I'm programming an online game for two reasons, one to familiarize myself with server/client requests in a realtime environment (as opposed to something like a typical web browser, which is not realtime) and to actually get my hands wet in that area, so I can proceed to actually properly design one. Anywho, I'm doing this in C++, and I'...

Can the C preprocessor be used to tell if a file exists?

I have a very large codebase (read: thousands of modules) that has code shared across numerous projects that all run on different operating systems with different c++ compilers. Needless to say, maintaining the build process can be quite a chore. There are several places in the codebase where it would clean up the code substantially if...

Why does my MFC app hang when I throw an exception?

If you throw an exception from inside an MFC dialog, the app hangs, even if you have a catch block in your code. It refuses to respond to the mouse or keyboard, and the only way to shut it down is to use Task Manager. Why I'm posting this question To my shame, there is a popular shrink-wrapped application that hangs every time it enc...

Debugging C++ STL containers in Windbg

Windbg fans claim that it is quite powerful and I tend to agree. But when it comes to debugging STL containers, I am always stuck. If the variable is on the stack, the !stl extension sometimes figures it out, but when a container with a complex type (e.g. std::vector<TemplateField, std::allocator<TemplateField> >) is on the heap or part ...

splice() on std::list and iterator invalidation

The 3-argument form of list::splice() moves a single element from one list to the other. SGI's documentation explicitly states that all iterators, including the one pointing to the element being moved remain valid. Roguewave's documentation does not say anything about iterator invalidation properties of splice() methods, whereas the C+...

C/C++: How to obtain the full path of current directory?

Is there a platform-agnostic and filesystem-agnostic method to obtain the full path of the directory from where a program is running using C/C++? Not to be confused with the current working directory. (Please don't suggest libraries unless they're standard ones like clib or STL.) (If there's no platform/filesystem-agnostic method, sugge...

How to redirect data to stdin within a single executable?

I am using cxxtest as the test framework for my C++ classes, and would like to figure out a way to simulate sending data to classes which would normally expect to receive it from standard input. I have several different files which I would like to send to the classes during different tests, so redirection from the command line to the te...

How much memory do Enums take?

For example if I have an Enum with two cases, does it make take more memory than a boolean? Languages: Java, C++ ...

Good Visual Studio 2005 tutorials?

Hi I guess this is quite a self-explanatory title. I need some tutorials showing the cool things of VS, but almost everything I find looks like being "How to conect a Web-app to a DB" kind of video-tutorial or a list of features and advertisement text. I am going to use it for C++ game programming. I'm new to this IDE but I heard it has...

Where can I find open source 2d bin packing algorithms?

I'm looking for open source (preferably c++) algorithms for 2d bin packing of rectangular and or irregular shapes. I've found several papers on the subject but no code. ...

What you think about throwing an exception for not found in C++?

I know most people think that as a bad practice but when you are trying to make your class public interface only work with references, keeping pointers inside and only when necessary, I think there is no way to return something telling that the value you are looking doesn't exist in the container. class list { public: value...

when to pass fuction arguments by reference and when by address?

Could anyone explain with some examples when it is better to call functions by reference and when it is better to call by address? ...

How to improve link performance for a large C++ application in VS2005

We have fairly large C++ application which is composed of about 60 projects in Visual Studio 2005. It currently takes 7 minutes to link in Release mode and I would like to try to reduce the time. Are there any tips for improving the link time? Most of the projects compile to static libraries, this makes testing easier since each one als...

How does Multiple C++ Threads execute on a class method

Hello, let's say we have a c++ class like: class MyClass { void processArray( <an array of 255 integers> ) { int i ; for (i=0;i<255;i++) { // do something with values in the array } } } and one instance of the class like: MyClass myInstance ; and 2 threads which call the processArray method o...

State of C++ Standard

I haven't kept up lately with the C++ world. Exactly where do things stand these days regarding the standard? Is TR1 adopted? Is there a TR2? How do these relate to C++0x? Are the subsumed? Has a decision been reached on threading yet? ...

Windows C++ dialog resizer class

I'm looking for a really good dialog resizer class that will stretch and shrink individual items as needed as the screen is resized. Stephan Keil has a good one (DlgResizeHelper) which basically resizes everything by a set ratio, but I'm looking for something smarter. For example: Icons should not resize Single-line text boxes should...

How to remove accents and tilde in a C++ std::string

Hi everyone, I have a problem with a string in C++ which has several words in Spanish. This means that I have a lot of words with accents and tildes. I want to replace them for their not accented counterparts. Example: I want to replace this word: "había" for habia. I tried replace it directly but with replace method of string class but...

How much overhead is there in calling a function in C++?

A lot of literature talks about using inline functions to "avoid the overhead of a function call". However I haven't seen quantifiable data. What is the actual overhead of a function call i.e. what sort of performance increase do we achieve by inlining functions? ...

Is it true that there is no need to learn C because C++ contains everything?

I am taking a class in C++ programming and the professor told us that there is no need to learn C because C++ contains everything in C plus object-oriented features. However, some others have told me that this is not necessarily true. Can anyone shed some light on this? ...

C++ performance vs. Java/C#

My understanding is that C/C++ produces native code to run on a particular machine architecture. Conversely, languages like Java and C# run on top of a virtual machine which abstracts away the native architecture. Logically it would seem impossible for Java or C# to match the speed of C++ because of this intermediate step, however I've...