@Navneet
This is my version of how delete and strlen must be working.Sorry the
presentation is not in correspondence with the style of the group.Apologies
for that,
*delete[]*
Suppose u are a compiler and u see a line like delete[] a,that will mean
that "Hey the programmer borrowed some memory from heap,he is now giving it
back,let me check with my table how much he took (My friend new must have
put it somewhere in the records).Ok done from the address of a to
a+no_of_blocks_allocated I have given back to heap and recorded it so. (2
steps).But the programmer may be greedy(and foolish) enough to use that
memory again,so I wont allow  that to happen till he makes a proper
request.So here I blacklist this memory for further access till he grants
another request for it."
So delete[] can do the work in 2 or 3 steps of assembler routine no matter
array is of 10 or 1000000.
Now see for *strlen*:
when the coder uses strlen he actually wants to say "Hey listen I am giving
you the beginning address of a bunch of random characters.I guarantee you
there is a bad guy with value 0 somewhere in there.Find me how many skips
you have to make from the starting address to get to that guy."
Now the poor function is left with no other option to search for that bad
guy looking in every box and counting how many times he skipped.Since he
can't make assumptions that's the only way he can obey his caller.
If you know any better way of searching for the bad guy '\0' let me know
please.



-- 
Saurabh Singh
B.Tech (Computer Science)
MNNIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to