M
mkaushik
Hi everyone,
Im just starting out with C++, and am curious to know how "delete []
<pointer>", knows about the number of memory locations to free.
I read somewhere that delete frees up space assigned to <pointer> by
"new". Does "new" create a list of pointer names and the size of the
memory array they point to? I also read that some compilers may store
the number of consec mem locations a pointer points to, just before the
first data element. Is that correct?
Also, if i used malloc() to make <pointer> point to a number of memory
locations, will calling "delete [] <pointer>" still work? if yes, how
does delete here know the number of memory locations to free? does the
malloc() implementation in C++ also create a pointer/memsize list like
"new"?
And lastly, if i made another pointer <pointer2> point to the same
location as <pointer>, would calling "delete [] <pointer2>" still free
up the correct number of locations?
Thanks in advance for answering my deluge of questions!
regards,
Mayank
Im just starting out with C++, and am curious to know how "delete []
<pointer>", knows about the number of memory locations to free.
I read somewhere that delete frees up space assigned to <pointer> by
"new". Does "new" create a list of pointer names and the size of the
memory array they point to? I also read that some compilers may store
the number of consec mem locations a pointer points to, just before the
first data element. Is that correct?
Also, if i used malloc() to make <pointer> point to a number of memory
locations, will calling "delete [] <pointer>" still work? if yes, how
does delete here know the number of memory locations to free? does the
malloc() implementation in C++ also create a pointer/memsize list like
"new"?
And lastly, if i made another pointer <pointer2> point to the same
location as <pointer>, would calling "delete [] <pointer2>" still free
up the correct number of locations?
Thanks in advance for answering my deluge of questions!
regards,
Mayank