background preloader

C++

Facebook Twitter

C++ - Unique class type Id that is safe and holds across library boundaries. Storing C++ template function definitions in a .CPP file. Why C++ Is Not “Back” I love C++. C++ taught me how to really write code. Back in the day I would study the intricacies of the language, Standard Template Library, and all the nuances of memory management and pointer arithmetic. Those were some seriously good times.

I remember reading Scott Meyers Effective C++ book series over and over again. Each time I would learn something new or grasp more of how to use C++. I’m saying all this just to let you know that I don’t hate C++. I love C++. There are plenty of excellent developers I know today that still use C++ and teach others how to use it and there is nothing at all wrong with that. So what is the problem then? The new message is wrong C++11 just came out recently and it seems like there is this big resurgence in interest in C++ development.

Now don’t get me wrong. There is one thing it didn’t become though—and this is the most important—more simple. Ok, so “NO” in caps is a bit harsh. Why do you want to learn C++? Wait! No! But, I want to learn C++ anyway. CUDA - Tutorial 4 - Atomic Operations | The Supercomputing Blog. This tutorial will discuss how to perform atomic operations in CUDA, which are often essential for many algorithms. Atomic operations are easy to use, and extremely useful in many applications. Atomic operations help avoid race conditions and can be used to make code simpler to write. What are atomic operations? Atomic operations are operations which are performed without interference from any other threads. How to avoid race conditions Fortunately, race conditions are easy to avoid in CUDA.

Example: int atomicAdd(int* address, int val); This atomicAdd function can be called within a kernel. Performance notes There are a couple things to beware of when using atomic operations. Also beware of serialization. Example of SLOW code: __shared__ totalSum; if (threadIdx.x == 0) totalSum = 0; __syncthreads(); int localVal = pValues[blockIdx.x * blockDim.x + threadIdx.x]; atomicAdd(&totalSum, 1); __syncthreads(); The code you see above is very simple. Compatibility notes Compiler issues. C - malloc-ating multidimensional array in function. C++ - How do I start a new CUDA project in Visual Studio 2008. Copying a struct containing pointers to CUDA device.

Boost C++

Using strings in C++ template metaprograms. Of all the reasons to love metaprogramming,1 probably the most compelling is that it lets us embed “little languages” in our programs. For example, we might want to express a parser for complex numbers this way, rather than explicitly writing a recursive descent parser ourselves: auto parse_complex = '(' >> double_ >> -(',' >> double_) >> ')' | double_; Or, instead of hand-coding the state machine for a CD player, we might want to express its transition table like this: auto player = Stopped + play [some_guard] / (some_action , start_playback) == Playing , Stopped + open_close/ open_drawer == Open , Stopped + stop == Stopped , Open + open_close / close_drawer == Empty , Empty + open_close / open_drawer == Open , Empty + cd_detected [good_disk_format] / store_cd_info == Stopped These two examples, using Boost’s Spirit and Meta State Machine libraries respectively, show how one can write a parser and a state machine.

Expression Templates auto all_caps = [A-Z]+; // SYNTAX ERROR A Better Way. C++ Reflection: Type MetaData: Introduction. C++ - How to add element by element of two STL vectors. Containers In Memory: How Big Is Big? This article appeared in C/C++ Users Journal, 19(1), January 2001. This column addresses two topics: An update on what's going on in the C++ standards process, and a technical question. For information about the former, see the accompanying "Standards Update" sidebar for breaking news about the 1998 C++ standard's first official update, whose ink should be drying as you read this, and how it affects you. The technical question is this: How much memory do the various standard containers use to store the same number of objects of the same type T? To answer this question, we have to consider two major items: Let's begin with a brief recap of dynamic memory allocation and then work our way back up to what it means for the standard library.

Memory Managers and Their Strategies: A Brief Survey Here, in brief, are two popular memory management strategies. In practice, you'll often see combinations of the above. The obvious next question is, Who selects the memory management strategy? 1. 2. Summary. C++ - Is it impossible to use stl map with struct. Sectorzero/maestri. James Reinders. INTEL, United States. C, C++ Programming Tutorials. Welcome! If you're new to C++, I recommend you purchase my ebook, Jumping into C++, a complete step-by-step guide for beginners. If you're looking for free tutorials, learn C++ with our C++ tutorial, starting at C++ Made Easy, Lesson 1 (all lessons) If you want to learn C instead, check out our C tutorial C Made Easy, Lesson 1 (all lessons) Want more advanced material on C, C++ graphics, game programming or algorithms? C++ Tutorial, C++ Made Easy: Learning to Program in C++ Learn C++ with this tutorial, designed for beginners and containing lots of examples, tips and simple explanations.

C Tutorial - C Made Easy This tutorial is based on the above tutorial, but uses only standard C language features. More Advanced C and C++ Language Feature Tutorials [Top] C++11 - the new C++ standard C++11 is the new C++ standard, and it's chock full of goodness for C++ programmers, old and new. C++ Standard Template Library (STL) tutorials Understanding Floating Point Numbers by Jeff Bezanson By Ben Marchant.

Solarian Programmer | My programming ramblings. C++11 multithreading tutorial - part 3 Posted on May 9, 2012 by Sol The code for this tutorial is on GitHub: In my previous two tutorials about C++11 threads: we’ve seen that C++11 allows us to use a clean syntax (compared with the one used by POSIX for e.g.) for managing multithread applications. The second tutorial presents an example of threads synchronization using mutex and atomic operations. We’ll start with a simple example of a C++11 thread with a member function: In the above example we use a dummy class with a public function that can be called from a thread, at line 21 in the source file you can see the way in which you can pass an argument to this function.

C++11 also allows us to use anonymous functions, or lambdas, in a thread: The above codes can be compiled with gcc-4.7 on Linux and Mac or with Visual Studio 11 on Windows. If you are interested in learning more about the new C++11 syntax I would recommend reading Professional C++ by M.