* Re: malloc
2002-06-17 21:26 malloc Earl R. Lapus
@ 2002-06-17 13:48 ` Glynn Clements
2002-06-17 14:32 ` malloc Jason P. Winters
2002-06-17 16:47 ` malloc Mehran Rezaei
2 siblings, 0 replies; 7+ messages in thread
From: Glynn Clements @ 2002-06-17 13:48 UTC (permalink / raw)
To: Earl R. Lapus; +Cc: linux-c-prog
Earl R. Lapus wrote:
> I tried doing this:
> ucp = (unsigned char *) malloc(0);
> it was successful and returned a valid address. I was kinda hoping
> it would do something weird...When I looked at the man page It said
> something like.. "If your application needs to generate empty objects,
> you may use malloc(0) for this purpose..."
>
> So my questions are:
> What do you mean when you say EMPTY OBJECT?
A block of memory which is zero bytes long. You can't store anything
in the block, but the returned pointer is guaranteed to be unique, in
that it differs from any other valid pointer.
> Does it ocuppy any memory storage?
Every block of memory returned from malloc() has a header, which
occupies memory.
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: malloc
2002-06-17 21:26 malloc Earl R. Lapus
2002-06-17 13:48 ` malloc Glynn Clements
@ 2002-06-17 14:32 ` Jason P. Winters
2002-06-17 16:47 ` malloc Mehran Rezaei
2 siblings, 0 replies; 7+ messages in thread
From: Jason P. Winters @ 2002-06-17 14:32 UTC (permalink / raw)
To: Earl R. Lapus; +Cc: linux-c-prog
> hi,
> I tried doing this:
> ucp = (unsigned char *) malloc(0);
Most malloc() calls have been "fixed" to return at least one byte of
useable memory when passed a 0, as too many people were doing that by
accident and crashing. (It might be more, like sizeof(int), but I'm
not sure).
After all, why would you call malloc to get nothing? So it assumes
you want *something* and returns it.
Ciao!
Jason
--
|UUCP jason@txt.com Who wills, Can.
|VOICE (408) 243-3425 Who tries, Does.
|LOCAL Hey, Jason! Who loves, Lives. o_.
|Disclaimer: Not me! I didn't do *THAT!* <|
|Local Disclaimer: I'm not here! A. McCaffrey 4
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: malloc
2002-06-17 21:26 malloc Earl R. Lapus
2002-06-17 13:48 ` malloc Glynn Clements
2002-06-17 14:32 ` malloc Jason P. Winters
@ 2002-06-17 16:47 ` Mehran Rezaei
2 siblings, 0 replies; 7+ messages in thread
From: Mehran Rezaei @ 2002-06-17 16:47 UTC (permalink / raw)
To: Earl R. Lapus, linux-c-prog
> hi,
> I tried doing this:
> ucp = (unsigned char *) malloc(0);
> it was successful and returned a valid address. I was kinda hoping
> it would do something weird...When I looked at the man page It said
> something like.. "If your application needs to generate empty objects,
> you may use malloc(0) for this purpose..."
>
> So my questions are:
> What do you mean when you say EMPTY OBJECT?
> Does it ocuppy any memory storage?
Hi there,
Of course it depends on the implementation. However, since Doug Lea'
allocator is the base and everybody else follows his setup here I am writing
about his allocator:
malloc(size_t n)
if "n" is zero, malloc returns a minimum-sized chunk (the minimum size is 16
bytes on most 32 bit machines, and 24 or 32 bytes on 64 bit machines).
From 16 bytes or 32 bytes returned, you do not see the header (2*address
size of machine - 64 bits in case of 32 bit machine). It leaves you 8 bytes
to use.
I believe gnu uses Doug Lea' allocator.
So long,
Mehran
^ permalink raw reply [flat|nested] 7+ messages in thread
* malloc
@ 2002-06-17 21:26 Earl R. Lapus
2002-06-17 13:48 ` malloc Glynn Clements
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Earl R. Lapus @ 2002-06-17 21:26 UTC (permalink / raw)
To: linux-c-prog
hi,
I tried doing this:
ucp = (unsigned char *) malloc(0);
it was successful and returned a valid address. I was kinda hoping
it would do something weird...When I looked at the man page It said
something like.. "If your application needs to generate empty objects,
you may use malloc(0) for this purpose..."
So my questions are:
What do you mean when you say EMPTY OBJECT?
Does it ocuppy any memory storage?
=========================
...what i want and what i need
IS and WILL always be FREE...
-brandon boyd-
=========================
^ permalink raw reply [flat|nested] 7+ messages in thread
* malloc
@ 2010-12-20 4:39 ratheesh k
2010-12-20 4:43 ` malloc Santosh Sivaraj
2010-12-27 18:51 ` malloc Uriel Corfa
0 siblings, 2 replies; 7+ messages in thread
From: ratheesh k @ 2010-12-20 4:39 UTC (permalink / raw)
To: linux-c-programming
Is the below statement right or wrong ?
malloc tries to allocate continous memmory space in virtual address
space. not in physical address space.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: malloc
2010-12-20 4:39 malloc ratheesh k
@ 2010-12-20 4:43 ` Santosh Sivaraj
2010-12-27 18:51 ` malloc Uriel Corfa
1 sibling, 0 replies; 7+ messages in thread
From: Santosh Sivaraj @ 2010-12-20 4:43 UTC (permalink / raw)
To: ratheesh k; +Cc: linux-c-programming
On 12/20/2010 10:09 AM, ratheesh k wrote:
> Is the below statement right or wrong ?
>
> malloc tries to allocate continous memmory space in virtual address
> space. not in physical address space.
It is right, you could have googled it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: malloc
2010-12-20 4:39 malloc ratheesh k
2010-12-20 4:43 ` malloc Santosh Sivaraj
@ 2010-12-27 18:51 ` Uriel Corfa
1 sibling, 0 replies; 7+ messages in thread
From: Uriel Corfa @ 2010-12-27 18:51 UTC (permalink / raw)
To: ratheesh k; +Cc: linux-c-programming
On Mon, Dec 20, 2010 at 5:39 AM, ratheesh k <ratheesh.ksz@gmail.com> wrote:
> Is the below statement right or wrong ?
>
> malloc tries to allocate continous memmory space in virtual address
> space. not in physical address space.
Hi,
This is true, but in theory, malloc doesn't have a notion of a virtual
or physical address space. Malloc is defined as : it tries to allocate
a contiguous memory chunk of at least the required size in a
system-defined pool. The question of setting up virtual address
spaces, of lazy allocation of physical pages, etc. is left up to the
underlying OS. In other terms : it's mmap(2) and brk(2) that take care
of this. Malloc relies on them for this kind of questions.
Regards,
--
Uriel Corfa
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-12-27 18:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-17 21:26 malloc Earl R. Lapus
2002-06-17 13:48 ` malloc Glynn Clements
2002-06-17 14:32 ` malloc Jason P. Winters
2002-06-17 16:47 ` malloc Mehran Rezaei
-- strict thread matches above, loose matches on Subject: below --
2010-12-20 4:39 malloc ratheesh k
2010-12-20 4:43 ` malloc Santosh Sivaraj
2010-12-27 18:51 ` malloc Uriel Corfa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).