I have some doubts regarding efficient memory management. Please help me
Hi ! These days I'm trying to understand how to efficiently manage heap-memory in C++ and how to tackle memory faults/leaks. I've added comments to help you to get what I'm doing and understand my problem better. So, I've this simple code inside main() function: ------------------------------------------------------------------------------------------------------------- char* str = new char; // allocating memory from heap for(unsigned long int i = 0; i < 1000; i++) *(str + i) = '#'; // as heap-memory is writable, so this should be okay delete str; // de-allocating the memory because it was allocated using new str = NULL; // preventing str from becoming a dangling pointer return 0; ------------------------------------------------------------------------------------------------------------- Let me know what I'm doing illegal for which my code terminates abnormally ( with a status of -1073741819, 0xC0000005 ). Also, provide a better approach to work with pointers and heap-memory. Thanks for your help! Side note: I'm using Code::blocks gnu gcc compiler, following the -std=c++11 language standards.