|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
another malloc question
if I do this
char * p = (char*) malloc(sizeof(char) * 30); p[20] = '\0'; free(p); How much memory did I free? was it the whole 30 bytes that I putted asside with the first statement, or just 21bytes caused by putting a binary 0 at offset 20? and if it is only 21 bytes, did i just created a memory leak?
__________________
Some day I'll create a smart quote to put here. |
|
#2
|
||||
|
||||
|
You freed 30 bytes.
|
|
#3
|
|||
|
|||
|
yes it frees 30 bytes of memory
'\0' is not a specifier for end memory location it is only a value stored at memory location it is use a specifier in C for end of string like $ symbol use in Assembly |
|
#4
|
||||
|
||||
|
thanks guys, specialy for the clarifing explanation.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > another malloc question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|