Home > Archive > C > August 2006 > Size of malloc'd?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| bwaichu@yahoo.com 2006-08-29, 6:56 pm |
| How do I determine the size of a previously malloc'd buffer?
char *buffer;
buffer = calloc(18, sizeof *buffer);
I cannot do a sizeof(buffer) since it would only return the size of the
pointer. I cannot do sizeof *buffer since it would only return the
size of the pointer type. Is there a right way to do this? Do I need
to manage this information in the program?
| |
|
|
bwaichu@yahoo.com wrote:
> How do I determine the size of a previously malloc'd buffer?
>
> char *buffer;
>
> buffer = calloc(18, sizeof *buffer);
>
> I cannot do a sizeof(buffer) since it would only return the size of the
> pointer. I cannot do sizeof *buffer since it would only return the
> size of the pointer type. Is there a right way to do this? Do I need
> to manage this information in the program?
This is covered by questions 7.27 and 7.28 in the FAQ list.
Basically, yes, you need to keep track of this for yourself.
--
| |
| Eric Sosman 2006-08-29, 6:56 pm |
|
bwaichu@yahoo.com wrote On 08/29/06 14:20,:
> How do I determine the size of a previously malloc'd buffer?
>
> char *buffer;
>
> buffer = calloc(18, sizeof *buffer);
>
> I cannot do a sizeof(buffer) since it would only return the size of the
> pointer. I cannot do sizeof *buffer since it would only return the
> size of the pointer type. Is there a right way to do this? Do I need
> to manage this information in the program?
This is Question 7.27 in the comp.lang.c Frequently
Asked Questions (FAQ) list
http://www.c-faq.com/
--
Eric.Sosman@sun.com
| |
| bwaichu@yahoo.com 2006-08-29, 6:56 pm |
|
Eric Sosman wrote:
> bwaichu@yahoo.com wrote On 08/29/06 14:20,:
>
> This is Question 7.27 in the comp.lang.c Frequently
> Asked Questions (FAQ) list
>
> http://www.c-faq.com/
Thanks for the link. The answer is what I expected.
Thanks!
|
|
|
|
|