c++ - What does new uint8_t(64) do? Do POD types have constructors? -
i made mistake in code. wrote like:
uint8_t * var = new uint8_t(64);
instead of:
uint8_t * var = new uint8_t[64];
the compiler (gcc) did not complain, @ execution, segfault
message:
... free(): invalid next size (fast): ...
running valgrind (memchecker): following diagnostic: invalid write of size 8
i tried gcc 4.7.2, producing 64-bit executable, running on linux. tried gcc 4.5.2, producing 32-bit executable , same kind of issue , diagnostic.
it looks memory gets allocated, not amount indicated between parenthesis.
what did do?
uint8_t * var = new uint8_t(64); // dynamically allocated 1 uint8_t object, , // initialize 64 uint8_t * var = new uint8_t[64]; // dynamically allocate space // 64 uint8_t objects (no initialization)
Comments
Post a Comment