Why is initializing a string to “” more efficient than the default constructor?

This is an intentional decision in libc++’s implementation of std::string. First of all, std::string has so-called Small String Optimization (SSO), which means that for very short (or empty) strings, it will store their contents directly inside of the container, rather than allocating dynamic memory. That’s why we don’t see any allocations in either case. In … Read more

What does the first “c” stand for in “calloc”?

According to an excerpt from the book Linux System Programming (by Robert Love), no official sources exist on the etymology of calloc. Some plausible candidates seem to be: Count or counted, because calloc takes a separate count argument. Clear, because it ensures that the returned memory chunk has been cleared. Brian Kernighan is reported to … Read more

Is make_shared really more efficient than new?

As infrastructure I was using llvm/clang 3.0 along with the llvm std c++ library within XCode4. Well that appears to be your problem. The C++11 standard states the following requirements for make_shared<T> (and allocate_shared<T>), in section 20.7.2.2.6: Requires: The expression ::new (pv) T(std::forward(args)…), where pv has type void* and points to storage suitable to hold … Read more

Why can’t clang with libc++ in c++0x mode link this boost::program_options example?

You need to rebuild boost using clang++ -stdlib=libc++. libc++ is not binary compatible with gcc’s libstdc++ (except for some low level stuff such as operator new). For example the std::string in gcc’s libstdc++ is refcounted, whereas in libc++ it uses the “short string optimization”. If you were to accidentally mix these two strings in the … Read more

How to compile/link Boost with clang++/libc++?

I didn’t know how to do this either. But after poking around in here, the getting started, and trial and error: $ ./bootstrap –with-toolset=clang $ ./b2 clean $ ./b2 toolset=clang cxxflags=”-stdlib=libc++” linkflags=”-stdlib=libc++” You’ll get lots of warnings. And the signals library will fail to build due to LWG 2059. But otherwise I think it works.

Using libstdc++ compiled libraries with clang++ -stdlib=libc++

What you’re seeing is the use of inline namespaces to achieve ABI versioning. What that means: The libstdc++ std::string is a different data structure than the libc++ std::string. The former is a reference counted design, whereas the latter is not. Although they are API compatible, they are not ABI compatible. That means that if you … Read more

Faster way to zero memory than with memset?

x86 is rather broad range of devices. For totally generic x86 target, an assembly block with “rep movsd” could blast out zeros to memory 32-bits at time. Try to make sure the bulk of this work is DWORD aligned. For chips with mmx, an assembly loop with movq could hit 64bits at a time. You … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)