On Wed, May 6, 2009 at 12:06 AM, Rick <[email protected]> wrote:
> At 5/5/2009 01:37 AM, you wrote:
>>[mod-- That isn't a C or C++ statement. At best it's an expression.
>>What does your reference manual say malloc does? --mod PN]
>>
>>hi,
>>     malloc(64)
>>
>>     what will this statement do?
>>
>>     allocate a memory space of 64bytes??
>>
>>     please reply
>
> Assuming your compiler does not flag this, it will likely give you a
> huge headache.
>
> Sure, you are allocating 64 bytes of memory, but you aren't assigning
> a pointer to point to it. So you can never free it -- or even use it
> for that matter.
>
> What is your point?

It looks like a badly phrased question of "How does malloc work?"  as
opposed to "What does malloc (in general) do?"

How malloc works differs from compiler to compiler, one method is
described here: <http://g.oswego.edu/dl/html/malloc.html> though there
are other ways. Google for [malloc algorihms] for other potential
methods.

Note that to use it, you don't need to know how it works (indeed, if
you've just started learning, it's usually a bad thing since you may
end up relying on behaviour of your your particular implementation
that doesn't exist in other implementations - treat it as the black
box that's described in your compiler's documentation.)

-- 
PJH

http://shabbleland.myminicity.com/com
http://www.chavgangs.com/register.php?referer=9375

Reply via email to