cppquizのブックマーク (4)

  • The "Empty Member" C++ Optimization

    The following article appeared in the August '97 "C++ Issue" of Dr. Dobb's Journal. The Standard C++ library is filled with useful templates, including extended versions of those found in the award-winning STL (See DDJ Mar95). These templates offer great flexibility, yet they are optimized for best performance in the common case. As useful as they are in programs, they are equally useful as exampl

    cppquiz
    cppquiz 2009/03/24
    アロケータは empty class の場合が多いので、実体のポインタを持つクラスに継承させて容量を節約する。
  • C++ Final Draft International Standard

    Programming languages --- C++ Languages de programmation --- C++ ISO/IEC JTC 1 Secretariat: ANSI Voting begins on: 1998-04-23 Voting terminates on: 1998-06-23 In accordance with the provisions of Council Resolution 21/1986, this document is circulated in the English language only. PRODUCTION NOTE: The dates in the headers of this FDIS, which currently read "1997", will be changed to "1998" bef

    cppquiz
    cppquiz 2009/03/19
    ISO C++ の最終ドラフト
  • More C++ Idioms/初回使用時生成(Construct On First Use) - Wikibooks

    自明でない(non-trivial)コンストラクタを持つ静的オブジェクトは使用前に初期化されねばならない。十分な注意を払わないと、初期化されていない非ローカル静的オブジェクトをアクセスしてしまう場合がある。 struct Bar { Bar () { cout << "Bar::Bar()\n"; } void f () { cout << "Bar::f()\n"; } }; struct Foo { Foo () { bar_.f (); } static Bar bar_; }; Foo f; Bar Foo::bar_; int main () {}

    cppquiz
    cppquiz 2009/03/19
    グローバル変数の未初期化使用を防ぐために。static 変数の参照を返す関数を使う。
  • memologue - __attribute__((init_priority(N))) で、C++のグローバル変数の初期化順序を制御する

    g++の __attribute__)((init_priority(N)))( なる機能の日語の解説が見当たらないので、いつものように紹介文を書いてみます。これは、C++のグローバル変数の初期化順序を制御するためのGCCの拡張機能(attribute)です。 ごく短い説明 動的な初期化が必要なC++のグローバル変数の定義に__attribute__)((init_priority(N)))(をくっつけると、.oファイル上で、その変数の初期化関数(コンストラクタ等)のアドレスが.ctorsではなく.ctors.M セクションに入ります。M は左0パディング5桁固定の数値で、M = 65535 - N です。あとは、shinhさんの2005/11の記事を。特に、リンカスクリプトのSORTのとこに注目、これにより初期化順がinit_priorityで指定した通りになります。Nが小さい程先に初

    memologue - __attribute__((init_priority(N))) で、C++のグローバル変数の初期化順序を制御する
    cppquiz
    cppquiz 2009/03/19
    グローバル変数が未初期化のまま使われる可能性。その回避策。
  • 1