0

As I know when I allocates char[] with size 200,000 and wanna init the whole buffer to zero. There's two ways for me:

const size_t SZ_LARGE_BUF = 200000;
  1. char *largeBuf = new char[SZ_LARGE_BUF]; memset(blablabla);
  2. char *largeBufWithInit = new char[SZ_LARGE_BUF]();

But the question is that when I run the 2nd code in linux, it's always get stuck, but the same code writing in windows VS2010 is ok. And the 1st code are both OK in Linux and Windows.

I wonder if there has any difference between memset and init syntax?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Bill Hoo
  • 647
  • 5
  • 21
  • Forget them both and use `std::vector largeBuf(200000);`. Much simpler and cleaner -- and works fine on both Windows and Linux. – Jerry Coffin Jul 19 '13 at 02:35
  • Thanks and I'll try vector, I find [sth](http://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new) in SO tells about this, but no info why `new char[200,000]()` stucked. I have one more question for you: if it's not 200,000 but 200, should I use `vector` or `char[200]`? – Bill Hoo Jul 19 '13 at 03:09
  • 3
    I'd use `vector` pretty much regardless of size. – Jerry Coffin Jul 19 '13 at 03:10

0 Answers0