2

I'd like to provide an API with the following C++ struct:

struct fixed_string64 {
  char array[64];
};
typedef fixed_string64 st64_t;

Most people tells you, it is generally not a good idea to do anything that eats up lots of stack space, but then, how much is "lots of" ?

In C++11, do we have something like is_stack_hungry<st64_t>::value ?

4

1 に答える 1

3

スタックのサイズは実装定義であり、システム/コンパイラからその情報を取得する標準的な方法を認識していません。--stackただし、ほとんどのコンパイラでは、( gccのように) スタック サイズを設定できるはずです。

ただし、「スタックを必要なだけ大きくする」ことは間違いなく私のアドバイスではありません。それが必要な場合は、何か間違ったことをしています。

たとえば、あなたの例では、メモリを割り当てて解放するためにコンストラクタとデストラクタを提供するだけです。

struct fixed_string64 {
  char* array;

  fixed_string64(){
    array = new char[64];
  }


  ~fixed_string64(){
    delete [] array;
  }
};
于 2013-09-20T16:00:26.700 に答える