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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -