-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hey can any one tell me what malloc 0 does,
ITYM
malloc(0);
And, the answer is yes and no.
it assigns space in memory i know that
Well, you know wrong, then
but is it usable and how many bytes does it allocate ,
FWIW, you ask for 0 bytes, you might just get zero bytes
allocation of 0 bytes is difficult-to-digest concept and still in the
memory.
The C standards (actually, the draft) says
7.20.3 Memory management functions
[snip]
If the size of the space requested is zero, the behavior is
implementation
defined: either a null pointer is returned, or the behavior is as if
the size were
some nonzero value, except that the returned pointer shall not be
used to
access an object.
The key phrase is "implementation defined". That means that we can't
answer your questions (or even grant that your assertions are correct
or not) without knowing the details of the C implementation you are
using. As I read it, so long as your C compiler/environment's
implementation documents it, malloc(0) could legitimately launch
Russian ICBM missles at your house or cause daemons to fly out of your
nose (the dreaded nasal daemons). Or, it could manipulate its
underlying storage management components so as to remove zero
user-accessable bytes of storage from the appropriate pool of free
storage and place it in a pool of used storage (such an operation would
likely involve an internal allocation of 0+n bytes, where the n
represents the data management overhead).
HTH
- --
Lew Pitcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12
iD8DBQFEqrmCagVFX4UWr64RAt3pAKCDJTOLbg+DhrtriNiA4PWSbKbJXACfSrtI
Axh2N6HHw/XOOkpbvGYYb2g=
=cE92
-----END PGP SIGNATURE-----