Git Product home page Git Product logo

facebook / folly Goto Github PK

View Code? Open in Web Editor NEW
27.1K 27.1K 5.4K 44.57 MB

An open-source C++ library developed and used at Facebook.

Home Page: https://groups.google.com/forum/?fromgroups#!forum/facebook-folly

License: Apache License 2.0

C++ 92.68% C 0.55% Shell 0.08% Python 2.26% Makefile 0.01% CSS 0.01% Ruby 0.02% Assembly 0.08% CMake 1.14% Batchfile 0.01% GDB 0.01% Cython 0.26% V 0.01% Starlark 2.89%

folly's Introduction

Folly: Facebook Open-source Library

Support Ukraine - Help Provide Humanitarian Aid to Ukraine.

What is folly?

Logo Folly

Folly (acronymed loosely after Facebook Open Source Library) is a library of C++17 components designed with practicality and efficiency in mind. Folly contains a variety of core library components used extensively at Facebook. In particular, it's often a dependency of Facebook's other open source C++ efforts and place where those projects can share code.

It complements (as opposed to competing against) offerings such as Boost and of course std. In fact, we embark on defining our own component only when something we need is either not available, or does not meet the needed performance profile. We endeavor to remove things from folly if or when std or Boost obsoletes them.

Performance concerns permeate much of Folly, sometimes leading to designs that are more idiosyncratic than they would otherwise be (see e.g. PackedSyncPtr.h, SmallLocks.h). Good performance at large scale is a unifying theme in all of Folly.

Check it out in the intro video

Explain Like I’m 5: Folly

Logical Design

Folly is a collection of relatively independent components, some as simple as a few symbols. There is no restriction on internal dependencies, meaning that a given folly module may use any other folly components.

All symbols are defined in the top-level namespace folly, except of course macros. Macro names are ALL_UPPERCASE and should be prefixed with FOLLY_. Namespace folly defines other internal namespaces such as internal or detail. User code should not depend on symbols in those namespaces.

Folly has an experimental directory as well. This designation connotes primarily that we feel the API may change heavily over time. This code, typically, is still in heavy use and is well tested.

Physical Design

At the top level Folly uses the classic "stuttering" scheme folly/folly used by Boost and others. The first directory serves as an installation root of the library (with possible versioning a la folly-1.0/), and the second is to distinguish the library when including files, e.g. #include <folly/FBString.h>.

The directory structure is flat (mimicking the namespace structure), i.e. we don't have an elaborate directory hierarchy (it is possible this will change in future versions). The subdirectory experimental contains files that are used inside folly and possibly at Facebook but not considered stable enough for client use. Your code should not use files in folly/experimental lest it may break when you update Folly.

The folly/folly/test subdirectory includes the unittests for all components, usually named ComponentXyzTest.cpp for each ComponentXyz.*. The folly/folly/docs directory contains documentation.

What's in it?

Because of folly's fairly flat structure, the best way to see what's in it is to look at the headers in top level folly/ directory. You can also check the docs folder for documentation, starting with the overview.

Folly is published on GitHub at https://github.com/facebook/folly.

Build Notes

Because folly does not provide any ABI compatibility guarantees from commit to commit, we generally recommend building folly as a static library.

folly supports gcc (5.1+), clang, or MSVC. It should run on Linux (x86-32, x86-64, and ARM), iOS, macOS, and Windows (x86-64). The CMake build is only tested on some of these platforms; at a minimum, we aim to support macOS and Linux (on the latest Ubuntu LTS release or newer.)

getdeps.py

This script is used by many of Meta's OSS tools. It will download and build all of the necessary dependencies first, and will then invoke cmake etc to build folly. This will help ensure that you build with relevant versions of all of the dependent libraries, taking into account what versions are installed locally on your system.

It's written in python so you'll need python3.6 or later on your PATH. It works on Linux, macOS and Windows.

The settings for folly's cmake build are held in its getdeps manifest build/fbcode_builder/manifests/folly, which you can edit locally if desired.

Dependencies

If on Linux or MacOS (with homebrew installed) you can install system dependencies to save building them:

# Clone the repo
git clone https://github.com/facebook/folly
# Install dependencies
cd folly
sudo ./build/fbcode_builder/getdeps.py install-system-deps --recursive

If you'd like to see the packages before installing them:

./build/fbcode_builder/getdeps.py install-system-deps --dry-run --recursive

On other platforms or if on Linux and without system dependencies getdeps.py will mostly download and build them for you during the build step.

Some of the dependencies getdeps.py uses and installs are:

  • a version of boost compiled with C++14 support.
  • googletest is required to build and run folly's tests.

Build

This script will download and build all of the necessary dependencies first, and will then invoke cmake etc to build folly. This will help ensure that you build with relevant versions of all of the dependent libraries, taking into account what versions are installed locally on your system.

getdeps.py currently requires python 3.6+ to be on your path.

getdeps.py will invoke cmake etc.

# Clone the repo
git clone https://github.com/facebook/folly
cd folly
# Build, using system dependencies if available
python3 ./build/fbcode_builder/getdeps.py --allow-system-packages build

It puts output in its scratch area:

  • installed/folly/lib/libfolly.a: Library

You can also specify a --scratch-path argument to control the location of the scratch directory used for the build. You can find the default scratch install location from logs or with python3 ./build/fbcode_builder/getdeps.py show-inst-dir.

There are also --install-dir and --install-prefix arguments to provide some more fine-grained control of the installation directories. However, given that folly provides no compatibility guarantees between commits we generally recommend building and installing the libraries to a temporary location, and then pointing your project's build at this temporary location, rather than installing folly in the traditional system installation directories. e.g., if you are building with CMake you can use the CMAKE_PREFIX_PATH variable to allow CMake to find folly in this temporary installation directory when building your project.

If you want to invoke cmake again to iterate, there is a helpful run_cmake.py script output in the scratch build directory. You can find the scratch build directory from logs or with python3 ./build/fbcode_builder/getdeps.py show-build-dir.

Run tests

By default getdeps.py will build the tests for folly. To run them:

cd folly
python3 ./build/fbcode_builder/getdeps.py --allow-system-packages test

build.sh/build.bat wrapper

build.sh can be used on Linux and MacOS, on Windows use the build.bat script instead. Its a wrapper around getdeps.py.

Build with cmake directly

If you don't want to let getdeps invoke cmake for you then by default, building the tests is disabled as part of the CMake all target. To build the tests, specify -DBUILD_TESTS=ON to CMake at configure time.

NB if you want to invoke cmake again to iterate on a getdeps.py build, there is a helpful run_cmake.py script output in the scratch-path build directory. You can find the scratch build directory from logs or with python3 ./build/fbcode_builder/getdeps.py show-build-dir.

Running tests with ctests also works if you cd to the build dir, e.g. (cd $(python3 ./build/fbcode_builder/getdeps.py show-build-dir) && ctest)

Finding dependencies in non-default locations

If you have boost, gtest, or other dependencies installed in a non-default location, you can use the CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH variables to make CMAKE look also look for header files and libraries in non-standard locations. For example, to also search the directories /alt/include/path1 and /alt/include/path2 for header files and the directories /alt/lib/path1 and /alt/lib/path2 for libraries, you can invoke cmake as follows:

cmake \
  -DCMAKE_INCLUDE_PATH=/alt/include/path1:/alt/include/path2 \
  -DCMAKE_LIBRARY_PATH=/alt/lib/path1:/alt/lib/path2 ...

Ubuntu LTS, CentOS Stream, Fedora

Use the getdeps.py approach above. We test in CI on Ubuntu LTS, and occasionally on other distros.

If you find the set of system packages is not quite right for your chosen distro, you can specify distro version specific overrides in the dependency manifests (e.g. https://github.com/facebook/folly/blob/main/build/fbcode_builder/manifests/boost ). You could probably make it work on most recent Ubuntu/Debian or Fedora/Redhat derived distributions.

At time of writing (Dec 2021) there is a build break on GCC 11.x based systems in lang_badge_test. If you don't need badge functionality you can work around by commenting it out from CMakeLists.txt (unfortunately fbthrift does need it)

Windows (Vcpkg)

Note that many tests are disabled for folly Windows builds, you can see them in the log from the cmake configure step, or by looking for WINDOWS_DISABLED in CMakeLists.txt

That said, getdeps.py builds work on Windows and are tested in CI.

If you prefer, you can try Vcpkg. folly is available in Vcpkg and releases may be built via vcpkg install folly:x64-windows.

You may also use vcpkg install folly:x64-windows --head to build against main.

macOS

getdeps.py builds work on macOS and are tested in CI, however if you prefer, you can try one of the macOS package managers

Homebrew

folly is available as a Formula and releases may be built via brew install folly.

You may also use folly/build/bootstrap-osx-homebrew.sh to build against main:

  ./folly/build/bootstrap-osx-homebrew.sh

This will create a build directory _build in the top-level.

MacPorts

Install the required packages from MacPorts:

  sudo port install \
    boost \
    cmake \
    gflags \
    git \
    google-glog \
    libevent \
    libtool \
    lz4 \
    lzma \
    openssl \
    snappy \
    xz \
    zlib

Download and install double-conversion:

  git clone https://github.com/google/double-conversion.git
  cd double-conversion
  cmake -DBUILD_SHARED_LIBS=ON .
  make
  sudo make install

Download and install folly with the parameters listed below:

  git clone https://github.com/facebook/folly.git
  cd folly
  mkdir _build
  cd _build
  cmake ..
  make
  sudo make install

folly's People

Contributors

aary avatar ahornby avatar andrewjcg avatar andriigrynenko avatar chadaustin avatar ddrcoder avatar dmm-fb avatar fugalh avatar gownta avatar iahs avatar igorsugak avatar joeloser avatar knekritz avatar leehowes avatar luciang avatar magedm avatar meyering avatar mzlee avatar orvid avatar ot avatar philippv avatar r-barnes avatar shixiao avatar simpkins avatar siyengar avatar terrelln avatar tudor avatar wez avatar willerz avatar yfeldblum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

folly's Issues

Does folly support socket-based servers?

I am interested in leveraging folly/io/, folly/io/async/, and some code in thrift/lib/cpp/src/thrift/. Do you have any advice on how to approach this?

For example, I'd like to create a simple UDP server and parse / process the above-L4 protocol myself while leveraging the L4 / async / socket code in these libraries. I am not sure I can (or should, or want to) express this protocol in the Thrift IDL.

Thrift has some of this socket server code, and also chromium/src/net/udp & associated chromium code, but ultimately I think it would be great if this was provided in folly. I see some potentially useful socket code in folly/test/SocketAddressTest.cpp.

Thank you!

OS X 10.9.4 build - missing binary operator before token "("

[ 11%] Building CXX object third-party/folly/CMakeFiles/folly.dir/folly/io/async/EventBase.cpp.o
In file included from /Users/ccarnell/Sites/hhvm/third-party/folly/folly/io/async/EventBase.cpp:23:0:
/Users/ccarnell/Sites/hhvm/third-party/folly/folly/ThreadName.h:25:42: error: missing binary operator before token "("
 #if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 12))
                                          ^
In file included from /Users/ccarnell/Sites/hhvm/third-party/folly/folly/io/async/NotificationQueue.h:23:0,
                 from /Users/ccarnell/Sites/hhvm/third-party/folly/folly/io/async/EventBase.cpp:24:
/Users/ccarnell/Sites/hhvm/third-party/folly/folly/io/async/EventFDWrapper.h:24:22: fatal error: features.h: No such file or directory
 #include <features.h>
                      ^
compilation terminated.
make[2]: *** [third-party/folly/CMakeFiles/folly.dir/folly/io/async/EventBase.cpp.o] Error 1
make[1]: *** [third-party/folly/CMakeFiles/folly.dir/all] Error 2
make: *** [all] Error 2

Tag Releases?

Can you tag releases so they are easier to lock in place?

Make Check failing on Centos 7

[root@localhost folly]# make check
Making check in .
make[1]: Entering directory `/root/folly/folly'
make[1]: Leaving directory `/root/folly/folly'
Making check in test
make[1]: Entering directory `/root/folly/folly/test'
Making check in .
make[2]: Entering directory `/root/folly/folly/test'
make  libgtestmain.la libgtest.la benchmark_test concurrent_skiplist_benchmark sorted_vector_types_test foreach_test hash_test timeout_queue_test conv_test range_test bits_test bit_iterator_test small_locks_test packed_sync_ptr_test small_vector_test discriminated_ptr_test fbstring_test_using_jemalloc thread_cached_int_test thread_local_test fbvector_test dynamic_test json_test scope_guard_test endian_test rw_spinlock_test synchronized_test concurrent_skiplist_test histogram_test group_varint_test map_util_test string_test producer_consumer_queue_test atomic_hash_array_test atomic_hash_map_test format_test fingerprint_test portability_test cpuid_test spooky_hash_v1_test spooky_hash_v2_test
make[3]: Entering directory `/root/folly/folly/test'
make[3]: *** No rule to make target `gtest-1.6.0/src/gtest-all.cc', needed by `gtest-1.6.0/src/libgtestmain_la-gtest-all.lo'.  Stop.
make[3]: Leaving directory `/root/folly/folly/test'
make[2]: *** [check-am] Error 2
make[2]: Leaving directory `/root/folly/folly/test'
make[1]: *** [check-recursive] Error 1
make[1]: Leaving directory `/root/folly/folly/test'
make: *** [check-recursive] Error 1

Centos 7 throws up the error:

These are installed:

yum -y install gcc gcc-c++ autoconf autoconf-archive automake boost-devel libtool lz4-devel lzma-devel snappy-devel zlib-devel glog-devel scons libtool gtest-devel

Built gflags, double-conversion and lzma.

What do I need to make this pass?

Gentoo: can't find double-conversion headers or library.

Configure fails to find the double-conversion.h header, which the Gentoo science overlay package installed into /usr/include/double-conversion. So if I add CPPFLAGS=-I/usr/include/double-conversion then it finds it but then fails on this error:

checking for ceil in -ldouble_conversion_pic... no

presumably because there is no pic library, just a non-pic library.

Is that a bug in Gentoo's package or in folly's configure? Thanks, cheers.

Benchmark && static initialisation order fiasco

It seems to me that folly::benchmarks (the vector) is subject to static initialisation order fiasco.

All my tests are constructed, "adding them" to benchmarks, and then benchmarks is initialised :(

Traits.h std::* declarations conflicts

Traits.h defines classes std::{pair,basic_string,vector,deque,list,set,map,shared_ptr}, however when compiling HHVM on OS X 10.9 (using clang and libc++) this results in conflicts à la:

In file included from hphp.y:11:
In file included from /Users/mcuelenaere/Projects/hhvm/hphp/compiler/parser/parser.h:23:
In file included from /Users/mcuelenaere/Projects/hhvm/hphp/runtime/base/exceptions.h:25:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/String.h:34:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Conv.h:27:
/Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/FBString.h:911:8: error: too few template arguments for class template 'basic_string'
  std::basic_string<Char> backend_;
       ^
/Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Traits.h:245:9: note: template is declared here
  class basic_string;
        ^
In file included from hphp.y:11:
In file included from /Users/mcuelenaere/Projects/hhvm/hphp/compiler/parser/parser.h:23:
In file included from /Users/mcuelenaere/Projects/hhvm/hphp/runtime/base/exceptions.h:25:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/String.h:34:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Conv.h:30:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Range.h:28:
/usr/local/include/glog/logging.h:1193:19: error: too few template arguments for class template 'vector'
             std::vector<std::string>* outvec);
                  ^
/Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Traits.h:251:9: note: template is declared here
  class vector;
        ^
In file included from hphp.y:11:
In file included from /Users/mcuelenaere/Projects/hhvm/hphp/compiler/parser/parser.h:23:
In file included from /Users/mcuelenaere/Projects/hhvm/hphp/runtime/base/exceptions.h:25:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/String.h:34:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Conv.h:30:
In file included from /Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Range.h:28:
/usr/local/include/glog/logging.h:1433:33: error: too few template arguments for class template 'vector'
GOOGLE_GLOG_DLL_DECL const std::vector<std::string>& GetLoggingDirectories();
                                ^
/Users/mcuelenaere/Projects/hhvm/third-party/folly/folly/Traits.h:251:9: note: template is declared here
  class vector;
        ^

I hackfixed these with this diff:

iff --git a/folly/Traits.h b/folly/Traits.h
index 2b94df1..eaed2c3 100644
--- a/folly/Traits.h
+++ b/folly/Traits.h
@@ -235,6 +235,7 @@ template <class T> struct IsZeroInitializable
  * although that is not guaranteed by the standard.
  */

+#if 0
 FOLLY_NAMESPACE_STD_BEGIN

 template <class T, class U>
@@ -260,6 +261,16 @@ template <class T>
   class shared_ptr;

 FOLLY_NAMESPACE_STD_END
+#else
+#include <utility>
+#include <string>
+#include <vector>
+#include <deque>
+#include <list>
+#include <set>
+#include <map>
+#include <memory>
+#endif

 namespace boost {

however, I'm unsure if this is the right approach.

UncaughtExceptionCounter.h not found

Hi all,

I'm trying to use folly for one of my projects. When I include <folly/dynamic.h> in my source code, it gave me errors as following:

In file included from /usr/local/include/folly/dynamic.h:522:
In file included from /usr/local/include/folly/dynamic-inl.h:25:
In file included from /usr/local/include/folly/Format.h:36:
In file included from /usr/local/include/folly/String.h:33:
/usr/local/include/folly/ScopeGuard.h:25:10: fatal error: 'folly/detail/UncaughtExceptionCounter.h' file not found

And also I wonder what would be the best way to include folly without having to specify absolute path to double-conversion in my Makefile.

Thank you very much!

  • Yunqi

error: '__builtin_ia32_crc32qi' was not declared in this scope

/tmp/hhvm-HZiR/hhvm-HHVM-2.3.2/hphp/third_party/folly/folly/Checksum.cpp: In function 'uint32_t folly::detail::crc32c_hw(const uint8_t*, size_t, uint32_t)':
/tmp/hhvm-HZiR/hhvm-HHVM-2.3.2/hphp/third_party/folly/folly/Checksum.cpp:42:63: error: '__builtin_ia32_crc32qi' was not declared in this scope
       sum = (uint32_t)__builtin_ia32_crc32qi(sum, data[offset]);
                                                               ^
/tmp/hhvm-HZiR/hhvm-HHVM-2.3.2/hphp/third_party/folly/folly/Checksum.cpp:50:43: error: '__builtin_ia32_crc32di' was not declared in this scope
     sum = __builtin_ia32_crc32di(sum, *src);
                                           ^
/tmp/hhvm-HZiR/hhvm-HHVM-2.3.2/hphp/third_party/folly/folly/Checksum.cpp:56:61: error: '__builtin_ia32_crc32qi' was not declared in this scope
     sum = (uint32_t)__builtin_ia32_crc32qi(sum, data[offset]);
                                                             ^
[  3%] Building C object hphp/third_party/libmbfl/mbfl/CMakeFiles/mbfl.dir/__/filters/mbfilter_jis.c.o
[  3%] Building C object hphp/third_party/timelib/CMakeFiles/timelib.dir/dow.c.o
make[2]: *** [hphp/third_party/folly/CMakeFiles/folly.dir/folly/Checksum.cpp.o] Error 1
make[1]: *** [hphp/third_party/folly/CMakeFiles/folly.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Compliation error on OS X: linux/futex.h: No such file or directory

After 79c25e6 folly can no longer compile on OS X.

Fails with detail/Futex.h:24:25: fatal error: linux/futex.h: No such file or directory.

Prior to 79c25e6 it would compile.

Reproduce (tested on 10.9.2 but should fail on others too).

Dependencies (if you don't have them)

brew install boost glog gflags jemalloc scons cmake autoconf automake libtool gcc49 
git clone https://code.google.com/p/double-conversion/
cd double-conversion/
cmake .
make
make install

Folly:

git clone https://github.com/facebook/folly.git folly
cd folly/folly/test
wget http://googletest.googlecode.com/files/gtest-1.6.0.zip
unzip gtest-1.6.0.zip
cd ../
autoreconf --install
CXX="/usr/local/bin/g++-4.9" CC="/usr/local/bin/gcc-4.9" ./configure
make

Error:

libtool: compile:  /usr/local/bin/g++-4.9 -DHAVE_CONFIG_H -I../. -I./io -I./test -pthread -I/usr/local/include -std=gnu++0x -g -O2 -MT json.lo -MD -MP -MF .deps/json.Tpo -c json.cpp -o json.o >/dev/null 2>&1
mv -f .deps/json.Tpo .deps/json.Plo
/bin/sh ./libtool  --tag=CXX   --mode=compile /usr/local/bin/g++-4.9 -DHAVE_CONFIG_H   -I../. -I./io -I./test -pthread -I/usr/local/include   -std=gnu++0x -g -O2 -MT MemoryIdler.lo -MD -MP -MF .deps/MemoryIdler.Tpo -c -o MemoryIdler.lo `test -f 'detail/MemoryIdler.cpp' || echo './'`detail/MemoryIdler.cpp
libtool: compile:  /usr/local/bin/g++-4.9 -DHAVE_CONFIG_H -I../. -I./io -I./test -pthread -I/usr/local/include -std=gnu++0x -g -O2 -MT MemoryIdler.lo -MD -MP -MF .deps/MemoryIdler.Tpo -c detail/MemoryIdler.cpp  -fno-common -DPIC -o .libs/MemoryIdler.o
In file included from detail/MemoryIdler.h:25:0,
                 from detail/MemoryIdler.cpp:17:
detail/Futex.h:24:25: fatal error: linux/futex.h: No such file or directory
 #include <linux/futex.h>
                         ^
compilation terminated.
make[2]: *** [MemoryIdler.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Checking out 6d89f3d resolves the above compile issue, and with a few additional fixes (https://gist.github.com/duedal/7887803) the entire lib can compile.

GTest "clock too coarse" failure despite upgraded kernel

Hey,

This is the log of the test suite from running "make check" on a fresh clone following the instructions of the README:

====================================
   folly 3.2: test/test-suite.log
====================================

# TOTAL: 36
# PASS:  35
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0

.. contents:: :depth: 2

FAIL: foreach_test
==================

[==========] Running 7 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 7 tests from Foreach
[ RUN      ] Foreach.ForEachRvalue
[       OK ] Foreach.ForEachRvalue (0 ms)
[ RUN      ] Foreach.ForEachKV
[       OK ] Foreach.ForEachKV (0 ms)
[ RUN      ] Foreach.ForEachKVBreak
[       OK ] Foreach.ForEachKVBreak (0 ms)
[ RUN      ] Foreach.ForEachKvWithMultiMap
[       OK ] Foreach.ForEachKvWithMultiMap (0 ms)
[ RUN      ] Foreach.ForEachEnumerate
[       OK ] Foreach.ForEachEnumerate (0 ms)
[ RUN      ] Foreach.ForEachEnumerateBreak
[       OK ] Foreach.ForEachEnumerateBreak (0 ms)
[ RUN      ] Foreach.ForEachRangeR
[       OK ] Foreach.ForEachRangeR (0 ms)
[----------] 7 tests from Foreach (0 ms total)

[----------] Global test environment tear-down
[==========] 7 tests from 1 test case ran. (0 ms total)
[  PASSED  ] 7 tests.
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0907 03:02:39.205322  1549 Benchmark.cpp:210] Check failed: 1 == ts.tv_nsec (1 vs. 4000000) Clock too coarse, upgrade your kernel.
*** Check failure stack trace: ***

I got this on a Microsoft Azure cloud compute server with the most up-to-date Linux kernel that is not RC:

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:        14.04
Codename:       trusty

3.16.2-031602-generic

Hope I'm not just being dumb. Looks like I was still able to run sudo make install without any problems.

Integrating existing Documentation into a Wiki

This is more of a housekeeping suggestion than anything else, but it may be useful to people trying to utilize the library is the existing contents of the /folly/docs folder were put into the Github wiki for this project. It may not be readily apparent to people new to the library where to find the documentation, and they may miss the /folly/docs folder during a search for it. It's not a high-importance suggestion, just an idea for making the understanding and immediate use of folly easier.

Unable to compile on CentOS release 6.2 (Final)

g++ -DHAVE_CONFIG_H -I. -I../. -I./io -I./test -lstdc++ -std=gnu++0x -pthread -I/usr/include -I/home/preilly/double-conversion/src/ -lboost_thread-mt -lboost_system -g -O2 -MT GenerateFingerprintTables.o -MD -MP -MF .deps/GenerateFingerprintTables.Tpo -c -o GenerateFingerprintTables.o test -f 'build/GenerateFingerprintTables.cpp' || echo './'build/GenerateFingerprintTables.cpp
mv -f .deps/GenerateFingerprintTables.Tpo .deps/GenerateFingerprintTables.Po
/bin/sh ./libtool --tag=CXX --mode=link g++ -lboost_thread-mt -lboost_system -g -O2 -L/home/preilly/double-conversion/ -o generate_fingerprint_tables GenerateFingerprintTables.o libfolly.la -ldouble_conversion_pic -lgflags -lglog
libtool: link: g++ -g -O2 -o .libs/generate_fingerprint_tables GenerateFingerprintTables.o -L/home/preilly/double-conversion/ ./.libs/libfolly.so -lboost_system -lboost_thread-mt -lpthread -ldouble_conversion_pic /usr/lib64/libgflags.so -lglog -pthread -Wl,-rpath -Wl,/usr/local/lib
./.libs/libfolly.so: undefined reference to boost::system::system_category()' ./.libs/libfolly.so: undefined reference toboost::system::generic_category()'
collect2: error: ld returned 1 exit status
make[2]: *** [generate_fingerprint_tables] Error 1
make[2]: Leaving directory /home/preilly/folly/folly' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory/home/preilly/folly/folly'
make: *** [all] Error 2

String.h specialize hash<string> causes problems for libc++.

The following simple program will produce error under libc++:

#include <cassert>
#include <string>
#include <unordered_map>

using namespace std;

namespace std {
template <class C>
struct hash<std::basic_string<C> > : private hash<const C*> {
  size_t operator()(const std::basic_string<C> & s) const {
    return hash<const C*>::operator()(s.c_str());
  }
};
}

const static unordered_map<string, int> m = {
  {"abc", 1},
  {"xyz", 2},
};

int main() {
  assert(m.find("abc") != m.end());
}

String.h shouldn't specialize hash function for libc++.

Compile error under libc++

In file included from Bits.cpp:17:
In file included from ./../folly/Bits.h:58:
In file included from ./../folly/Portability.h:191:
./../folly/detail/FunctionalExcept.h:22:1: error: unknown type name '_LIBCPP_BEGIN_NAMESPACE_STD'
FOLLY_NAMESPACE_STD_BEGIN

Obviously _LIBCPP_BEGIN_NAMESPACE_STD is not recognized. One needs to include any standard header to get the definition of _LIBCPP_BEGIN_NAMESPACE_STD. Or include <__config>.

folly/Demangle.h not being installed

when I trying fbthrift I found this
"
/home/lee/usr/include/folly/String.h:33:28: fatal error: folly/Demangle.h: No such file or directory #include "folly/Demangle.h"
"

AtomicHashArray

Is there a reason why AtomicHashMap supports only stateless allocators? It seems like an oversight, as It would be convenient to be able to support stateful allocation for containers stored in shared memory.

Gentoo: can't find double-conversion headers or library.

Configure fails to find the double-conversion.h header, which the Gentoo science overlay package installed into /usr/include/double-conversion. So if I add CPPFLAGS=-I/usr/include/double-conversion then it finds it but then fails on this error:

checking for ceil in -ldouble_conversion_pic... no

presumably because there is no pic library, just a non-pic library.

Is that a bug in Gentoo's package or in folly's configure? Thanks, cheers.

Incorrect include paths at build time

configure.ac has an incorrect build path:

AC_SUBST(AM_CPPFLAGS, '-I../$(top_srcdir)'" "'-I$(top_srcdir)/io'" "'-I$(top_srcdir)/test'" -lstdc++ $CXX_FLAGS $BOOST_CPPFLAGS")

Should be:

AC_SUBST(AM_CPPFLAGS, '-I$(top_srcdir)/..'" "'-I$(top_srcdir)/io'" "'-I$(top_srcdir)/test'" -lstdc++ $CXX_FLAGS $BOOST_CPPFLAGS")

Compiler cannot found crashOnError : 'crashOnError_' was not declared in this scope

I tried to change crashOnError to above public type, but cannot build source successes.

Fomatter{ 
private:
bool crashOnError_{true}; 
public:
...

};

Thus, Source retrieve to old state of source code. An error show as below:

In file included from /usr/include/c++/4.6/ext/hash_set:61:0,
                 from .././folly/String.h:25,
                 from .././folly/Format.h:36,
                 from .././folly/dynamic-inl.h:25,
                 from .././folly/dynamic.h:522,
                 from json.h:44,
                 from Benchmark.cpp:21:
/usr/include/c++/4.6/backward/backward_warning.h:33:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
In file included from .././folly/dynamic-inl.h:25:0,
                 from .././folly/dynamic.h:522,
                 from json.h:44,
                 from Benchmark.cpp:21:
.././folly/Format.h:159:8: error: function definition does not declare parameters
.././folly/Format.h: In member function 'void folly::Formatter<containerMode, Args>::setCrashOnError(bool)':
.././folly/Format.h:76:5: error: 'crashOnError_' was not declared in this scope
In file included from .././folly/Format.h:358:0,
                 from .././folly/dynamic-inl.h:25,
                 from .././folly/dynamic.h:522,
                 from json.h:44,
                 from Benchmark.cpp:21:
.././folly/Format-inl.h: In member function 'void folly::Formatter<containerMode, Args>::handleFormatStrError() const':
.././folly/Format-inl.h:152:7: error: 'crashOnError_' was not declared in this scope

Bits.h in MSVC

It seems the effort to port Bits.h to MSVC have a little bit problem:
__builtin_ffs(x) won't return 0 when x is not 0, but _BitScanForward(index, mask) can load index to zero when mask's LSB is 1.

I make this:

#ifdef _MSC_VER
    unsigned long index;
    return (_BitScanForward(&index, x) ? index + 1 : 0);
#else
    return __builtin_ffs(x);
#endif

std:: error when compiling hhvm using the homebrew formula in OS X Yosemite

Linking CXX executable gen-infotabs
Linking CXX executable gen-class-map
Undefined symbols for architecture x86_64:
Undefined symbols for architecture x86_64:
  "std::__throw_logic_error(char const*)", referenced from:
  "std::__throw_logic_error(char const*)", referenced from:
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::basic_fbstring(char const*, std::__1::allocator<char> const&) in gen-class-map.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::basic_fbstring(char const*, std::__1::allocator<char> const&) in idl.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::basic_fbstring(char const*, std::__1::allocator<char> const&) in libfolly.a(Demangle.cpp.o)
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::basic_fbstring(char const*, std::__1::allocator<char> const&) in idl.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::basic_fbstring(char const*, std::__1::allocator<char> const&) in libfolly.a(Demangle.cpp.o)
  "std::__throw_out_of_range(char const*)", referenced from:
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const in gen-infotabs.cpp.o
  "std::__throw_out_of_range(char const*)", referenced from:
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::substr(unsigned long, unsigned long) const in idl.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const in gen-class-map.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const in idl.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::substr(unsigned long, unsigned long) const in idl.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const in idl.cpp.o
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const in libfolly.a(json.cpp.o)
      folly::basic_fbstring<char, std::__1::char_traits<char>, std::__1::allocator<char>, folly::fbstring_core<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const in libfolly.a(json.cpp.o)
ld: symbol(s) not found for architecture x86_64
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)clang: error
: linker command failed with exit code 1 (use -v to see invocation)

Possibility of supporting Folly on Mac OS X?

Currently there are some non-portable items that breaks the build in HHVM, Just wondering the possibility of the Mac OS X fix and the PR you intend to receive.

Thanks!

In file included from /Volumes/ramdisk/hhvm/third-party/folly/folly/Baton.h:26:0,
                 from /Volumes/ramdisk/hhvm/third-party/folly/folly/LifoSem.h:28,
                 from /Volumes/ramdisk/hhvm/third-party/folly/folly/experimental/wangle/concurrent/LifoSemMPMCQueue.h:19,
                 from /Volumes/ramdisk/hhvm/third-party/folly/folly/experimental/wangle/concurrent/ThreadPoolExecutor.h:19,
                 from /Volumes/ramdisk/hhvm/third-party/folly/folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.h:18,
                 from /Volumes/ramdisk/hhvm/third-party/folly/folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp:17:
/Volumes/ramdisk/hhvm/third-party/folly/folly/detail/Futex.h:24:25: fatal error: linux/futex.h: No such file or directory
 #include <linux/futex.h>
                         ^
compilation terminated.
make[2]: *** [third-party/folly/CMakeFiles/folly.dir/folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.cpp.o] Error 1
make[1]: *** [third-party/folly/CMakeFiles/folly.dir/all] Error 2

Traits.h produces error from FOLLY_ASSUME_FBVECTOR_COMPATIBLE_*

It seams like if another library is included before folly/Traits.h (which gets included from all over folly) that has any kind of use of boost::has_nothrow_constructor on basic types (std::shared_ptr, boost::shared_ptr, others) the folly FOLLY_ASSUME_FBVECTOR_COMPATIBLE_* macros end up producing errors.

More detail:
It seams like if there is a use templated use of a std::shared_ptr or that depends on not fully defined type (see bellow with External) then folly will blow up. In my case I have an external library that uses std::shared_ptr and it hides SomeType due to the PIMPL idiom.

Reduced test case:

#include <string>
#include <memory>

// Some other header would do this

#include <boost/type_traits.hpp>

struct External;

template <typename T>
class Check : public  boost::has_nothrow_constructor<T>
{ };

static_assert(Check<std::shared_ptr<External>>::value, "txt");

// Then we include folly

#include <folly/Traits.h>

int main(int argc, char* argv[])
{
    return 0;
}

Compilation error

In file included from test2.cpp:18:0:
/usr/local/include/folly/Traits.h:448:1: error: partial specialization of ‘boost::has_nothrow_constructor<std::shared_ptr<_Tp1> >’ after instantiation of ‘boost::has_nothrow_constructor<std::shared_ptr<External> >’ [-fpermissive]
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::shared_ptr);
 ^

EDIT: There was another unrelated issue in this ticket. I fixed it... but the original problem still remains.

Windows support for folly

Allow folly to build and work on windows systems - using

  1. Visual Studio 2013 [VC++12](and above) compilers (anything below is missing too many c++11 features)
  2. Clang on windows llvm 3.4 and higher
  3. MinGW-w64 4.8 and higher
    with support for Windows 7 and higher operating systems (this includes server 2012 and 2012 r2)

This is necessary to allow hhvm to link and use folly

Visual Studio 2013 is missing several c++11 features which folly uses, which will make porting a bit of a pain. Currently these have been identified as:

  1. constexpr
  2. noexcept
  3. default move/assign methods (these do work but you have to write them by hand, =default will fail)

In addition windows in general is missing several posix apis in use. However, only very platform specific futex and elf/dwarf features do not have analogs in the windows apis. So these can be "faked" with posix api wrappers, and perhaps later with pluggable direct calls into windows apis. Even the futex use could be replaced with some of the new threading and atomic calls available since windows 7.

All the currently in use dependencies compile and work properly on windows

  1. double-encoding (using 2.1)
  2. glog
  3. gflags
  4. pthreads (pthreads-win32 which works on 64 bit now or winpthreads)
  5. snappy
  6. zlib
  7. lzma (via xz utils)
  8. lz4
  9. boost
  10. libevent
  11. gtest

This will necessitate a friendlier build system (that's preferably a bit more up to date than the current autotools system), builds of dependencies for deps that don't distribute pre-build binaries (should always be sure that runtimes match), fixes for c++11 features not implemented in msvc, and posix wrappers/adjustments for platform dependent implementations for folly features.

AsyncIO

In AsyncIO property pending_ has type ssize_t, but pending() returns size_t. Its normal?

typos in code

Here is a list of typos, i found in your code:

facebook-folly-27494a2/folly/AtomicHashArray-inl.h:255: noticably ==> noticeably
facebook-folly-27494a2/folly/README:21: enviroment ==> environment
facebook-folly-27494a2/folly/PackedSyncPtr.h:108: Syncronization ==> Synchronization
facebook-folly-27494a2/folly/ConcurrentSkipList.h:256: everytime ==> every time
facebook-folly-27494a2/folly/FBString.h:1487: occurences ==> occurrences
facebook-folly-27494a2/folly/FBString.h:2227: compatiblity ==> compatibility
facebook-folly-27494a2/folly/test/PackedSyncPtrTest.cpp:114: succesfully ==> successfully
facebook-folly-27494a2/folly/test/ConcurrentSkipListBenchmark.cpp:582: multi-thread ==> multithread
facebook-folly-27494a2/folly/test/ThreadCachedIntTest.cpp:158: Acheives ==> Achieves
facebook-folly-27494a2/folly/docs/AtomicHashMap.md:29: syncronization ==> synchronization

Best regards

Ettl Martin

make install incomplete? Had to copy a few headers manually

From the double conversion library into the /usr/local/include/folly folder: double-conversion.h utils.h
Also /usr/local/include/folly/Preprocessor.h was missing, I copied it there from the source directory.

(also, the README suggests that the LDFLAGS and CPPFLAGS variables should be altered in the terminal session, but that didn't work for me, so I copied the lines into the configure.ac file right after the "checks for header files" comment)

I'm on OpenSuse 12.1 64bit, gcc 4.7. Might be a local problem from my side.

Who can tell me what folly can do?

Sorry, I am a new beginner of Folly.

But I want to know what folly can do? but right now, no wiki page for this common issue.

Thanks
Longda

Absolute path in comment (FBString.h)

The comment at FBString.h:74 references an absolute path to

/home/engshare/third-party/src/libgcc/libgcc-4.6.2/gcc-4.6.2-20111027/libstdc++-v3/include/bits/basic_string.h

for further information.

fbvector of std:maps is crashing

Hi,

we have an older version of folly running (how do I check the version number?) and I tried compiling the newest version available but I was stuck on some boost-library issue in configure. [A step by step introduction how to get folly running and tests started would be very helpful btw.]

Anyway, the following code crashes at the foobar line in our version.
Could you check whether this is fixed already?
(sorry, that this is not with google test)

BOOST_AUTO_TEST_CASE( test_folly_fbvector_test )
{
// using a std::vector instead of fbvector will work
folly::fbvector<std::map<std::string, std::string>> vec_of_maps;

vec_of_maps.push_back(std::map<std::string, std::string>());
vec_of_maps.push_back(std::map<std::string, std::string>());
BOOST_CHECK(vec_of_maps.size() == 2);

// inserting into the second map works
vec_of_maps[1]["hello"] = "world";
BOOST_CHECK(vec_of_maps[0].size() == 0);
BOOST_CHECK(vec_of_maps[1].size() == 1);

// inserting into first map should work (but crashes)
vec_of_maps[0]["foo"] = "bar";
BOOST_CHECK(vec_of_maps[0].size() == 1);
BOOST_CHECK(vec_of_maps[1].size() == 1);

}

The addition of Codel to experimental/wangle/concurrent breaks thpp

thpp links against both folly and fbthrift. With the addition of Codel to folly, both libraries define codel_interval and codel_target_delay in the top-level namespace. This name collision prevents thpp from building successfully.

I got thpp to build by removing Codel from folly and re-building both.

OS X 10.9.4 - error: constructor priorities are not supported

Compiling HHVM:

[  8%] Building CXX object third-party/folly/CMakeFiles/folly.dir/folly/Version.cpp.o
In file included from /Users/ccarnell/Sites/hhvm/third-party/folly/folly/Version.cpp:17:0:
/Users/ccarnell/Sites/hhvm/third-party/folly/folly/VersionCheck.h:78:55: error: constructor priorities are not supported
   __attribute__((constructor(101))) void versionCheck() { \
                                                       ^
/Users/ccarnell/Sites/hhvm/third-party/folly/folly/Version.cpp:21:1: note: in expansion of macro 'FOLLY_VERSION_CHECK'
 FOLLY_VERSION_CHECK(folly, FOLLY_VERSION)
 ^
make[2]: *** [third-party/folly/CMakeFiles/folly.dir/folly/Version.cpp.o] Error 1
make[1]: *** [third-party/folly/CMakeFiles/folly.dir/all] Error 2
make: *** [all] Error 2

facebook/hhvm#3227

folly should be able to use system libraries

Folly uses two external libs during the build: double-conversion and gtest. The installation instructions suggest to download the sources and build by itself.

But there are systems with great package managers (basically any Linux distro) that most likely have these libraries in their packages. Linux Arch for example has both these libs. It would be great if build system was able to use the system dependencies if they are already installed.

gcc-isms

folly contains a decent amount of gcc'isms. Let me enumerate some of them:

  1. Portability.h uses __GNUC_PREREQ macro, which is basically available only on gcc and only after features.h is included.
  2. Several headers include stuff from bits/* which is definitely no-go, since it contains libstdc++ internal stuff and might now be available on, e.g. libc++-only system

warning

gcc version 4.8.2 20140206
OS: Linux nova 3.13.7-1-ARCH

When including the following header in my code

define FBSTRING_CONSERVATIVE

include <folly/AtomicHashMap.h>

I am getting a warning below. What's the proper way of getting rid of it aside from defining no-deprecated compilation option?

In file included from /usr/include/c++/4.8.2/ext/hash_set:60:0,
from /opt/env/prod/Folly/Current/include/folly/FBString.h:101,
from /opt/env/prod/Folly/Current/include/folly/Conv.h:27,
from /opt/env/prod/Folly/Current/include/folly/Exception.h:26,
from /opt/env/prod/Folly/Current/include/folly/detail/ThreadLocalDetail.h:30,
from /opt/env/prod/Folly/Current/include/folly/ThreadLocal.h:53,
from /opt/env/prod/Folly/Current/include/folly/ThreadCachedInt.h:31,
from /opt/env/prod/Folly/Current/include/folly/AtomicHashArray.h:41,
from /opt/env/prod/Folly/Current/include/folly/AtomicHashMap.h:93,
...
/usr/include/c++/4.8.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
#warning
^

FBVector.md not the complete story..

From the "FBVector.md" page I would like to add more comment then an "issue".

Now since the focus is on "performance" a few key things need to be pointed out about "std::vector"
or any similar implementation. For that matter any kind of memory container.

To get real performance out of any program you need to know what is going on "under the hood".
At least for key parts like an STL containers.
Programmers of any language just thinking in terms of high level abstractions, thinking in ways of just
"this is how it' done", this is what my teacher, or my CS text book says, etc., just dropping things here and there
are never really going to get real performance unless it happens by accident.
Not to mention suffer from other evils like code bloat to some degree or another.

Performance is particularly important for real time applications like games, simulations, etc.
And really wouldn't we all like better performing day to day applications and tools that we use all the time?

Read Pete Isensee articles where he breaks down a lot of STL use in game development.
His Game Programming Gems chapters and GameDev articles, etc., like "Common C++ Performance Mistakes in Games".
You can get most of it free with source code on his site: www tantalon com

The key points with vectors:

  1. Use ".reserve()" when you know how many exact or maximum elements you need.
    No performance hit for growing an array when there isn't.
    Note also at least with a Windows OS and it's paging mechanism that physical RAM pages are not actually until they touched. So you can ".reserve()" a bit more then you need without issue.

  2. Use "resize()" vrs "clear()" to reset element count to zero. "clear()" will cause the vector allocation to free (and thus need to be re-allocated again) where "resize()" doesn't.

  3. For CPUs where it matters (read all modern day PC CPUs) make things cache aligned when possible.
    If you can (allocations are not to too large, etc.) use align 16 containers.
    Then use a custom STL Allocator that provides align 16 blocks. Easier then you think, use Pete's source code and read the articles.

Also a good on the subject is "Data-Oriented Design (Or Why You Might Be Shooting Yourself in The Foot With OOP)" by
Noel Llopis, et al.

fatal error: 'bits/c++config.h' file not found

$ clang --version
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
folly/FBString.h:936:8: error: too few template arguments for class template 'basic_string'
  std::basic_string<Char> backend_;
       ^

folly/Traits.h:243:9: note: template is declared here
  class basic_string;
        ^

folly/FBString.h:2315:8: error: no member named '__ostream_insert' in namespace 'std'
  std::__ostream_insert(os, str.data(), str.size());
  ~~~~~^

folly/Range.h:42:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>
         ^
$ locate c++config.h
/usr/include/c++/4.2.1/bits/c++config.h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.