Question about dynamically allocated memory
-
Hi! I have a question about dynamically allocated memory, actually about cleaning that memory. For example I compile and run this piece of code:
char *pString = NULL; if ( (pString = new char [100]) == NULL ) exit( EXIT_FAILURE ); ... <--- Use pString delete [] pString;
The question is how does the program know how much memory (how many bytes) to free (deallocate)? Isn't it compulsory to specify the number of bytes between the two brackets in order to be sure that it will free all the dynamically allocated memory? :confused: Any suggestions would be greatly appreciated! Thanks in advance! -
Hi! I have a question about dynamically allocated memory, actually about cleaning that memory. For example I compile and run this piece of code:
char *pString = NULL; if ( (pString = new char [100]) == NULL ) exit( EXIT_FAILURE ); ... <--- Use pString delete [] pString;
The question is how does the program know how much memory (how many bytes) to free (deallocate)? Isn't it compulsory to specify the number of bytes between the two brackets in order to be sure that it will free all the dynamically allocated memory? :confused: Any suggestions would be greatly appreciated! Thanks in advance!Each heap allocation keeps track of its size.
Steve
-
Hi! I have a question about dynamically allocated memory, actually about cleaning that memory. For example I compile and run this piece of code:
char *pString = NULL; if ( (pString = new char [100]) == NULL ) exit( EXIT_FAILURE ); ... <--- Use pString delete [] pString;
The question is how does the program know how much memory (how many bytes) to free (deallocate)? Isn't it compulsory to specify the number of bytes between the two brackets in order to be sure that it will free all the dynamically allocated memory? :confused: Any suggestions would be greatly appreciated! Thanks in advance!Prasad Notifier using ATL
-
Hi! I have a question about dynamically allocated memory, actually about cleaning that memory. For example I compile and run this piece of code:
char *pString = NULL; if ( (pString = new char [100]) == NULL ) exit( EXIT_FAILURE ); ... <--- Use pString delete [] pString;
The question is how does the program know how much memory (how many bytes) to free (deallocate)? Isn't it compulsory to specify the number of bytes between the two brackets in order to be sure that it will free all the dynamically allocated memory? :confused: Any suggestions would be greatly appreciated! Thanks in advance! -
:confused: Did you read his question ?? The link you posted has nothing to do with new and delete, it is purely C programming (alloc, malloc, realloc, ...). When posting a link, at least take the time to verify if it contains valuable information for the OP. Just googling and pasting the first link that cames up is not really helpfull.
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
:confused: Did you read his question ?? The link you posted has nothing to do with new and delete, it is purely C programming (alloc, malloc, realloc, ...). When posting a link, at least take the time to verify if it contains valuable information for the OP. Just googling and pasting the first link that cames up is not really helpfull.
Cédric Moonen Software developer
Charting control [Updated - v1.1]It seems I must read complete a thread not only title,thanks for remind,sometime when I see a title I guess body is like title (thanks), but i dont think that stuff and paste link is good,yes?
_**
**_
WhiteSky
-
It seems I must read complete a thread not only title,thanks for remind,sometime when I see a title I guess body is like title (thanks), but i dont think that stuff and paste link is good,yes?
_**
**_
WhiteSky
WhiteSky wrote:
It seems I must read complete a thread not only title
:omg::wtf: Of course !! That seems logical no ? How can you describe completely a problem in one single title line ??
WhiteSky wrote:
but i dont think that stuff and paste link is good
It depends. Sometimes it is usefull, but sometimes it can be really annoying. For example if that links to a lot of text and if the OP needs to search a lot to find the information, it is in general not very valuable. And if you provide a link to something you googled for, then at least verify that it contains the information. We ask the people who post the questions to have some respect for the other (so formulate the questions correctly, use proper english if possible, ...) but the opposite is true also.
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
WhiteSky wrote:
It seems I must read complete a thread not only title
:omg::wtf: Of course !! That seems logical no ? How can you describe completely a problem in one single title line ??
WhiteSky wrote:
but i dont think that stuff and paste link is good
It depends. Sometimes it is usefull, but sometimes it can be really annoying. For example if that links to a lot of text and if the OP needs to search a lot to find the information, it is in general not very valuable. And if you provide a link to something you googled for, then at least verify that it contains the information. We ask the people who post the questions to have some respect for the other (so formulate the questions correctly, use proper english if possible, ...) but the opposite is true also.
Cédric Moonen Software developer
Charting control [Updated - v1.1]Cedric Moonen wrote:
Of course !! That seems logical no ? How can you describe completely a problem in one single title line ??
"How to show a bmp file on background of dialog" a title i think see yesterday not sure well anyway when you see this sentence what do you think?so its possible of course not always. -------------------------- ...but sometime Im wondering because you see a question and sender explain a lot of then you search and find a site when you answer to sender he say its very helpful,great and... but i want to know why sender doesnt search or sometime some one ask what is ?(it) without any try
_**
**_
WhiteSky