Re: Size of malloc'd?





bwaichu@xxxxxxxxx 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@xxxxxxx

.



Relevant Pages

  • Re: return string
    ... the const tells you that the field name is not going to be modified, the CString & ... is your responsibility to make sure you do not exceed the buffer size. ... use the obsolete data type 'char' for any purpose ... NEVER pass a pointer to a buffer without passing the size!!!!! ...
    (microsoft.public.vc.mfc)
  • How to get the PID and VID of a USB Mass Storage Device
    ... char driveName; ... memset (buffer, 0, sizeof (buffer)); ... char serialNumber; ...
    (microsoft.public.development.device.drivers)
  • Re: problem with memcpy and pointers/arrays confusion - again
    ... int line, unsigned long *total_mem) ... That's a long pointer address... ... If sizeof > sizeof which is ... if you allocate for char with sizeof < sizeof, ...
    (comp.lang.c)
  • some unanswered questions on C
    ... but what exactly is an uninitialised pointer? ... what i want to ask is that when i declare my buffer for fgets as ... my seg fault disappears... ... if the man page says that strcat returns a 'char *' and since the name ...
    (comp.unix.programmer)
  • Re: unusual behaviour of program under linux....
    ... but what exactly is an uninitialised pointer? ... what i want to ask is that when i declare my buffer for fgets as ... my seg fault disappears... ... if the man page says that strcat returns a 'char *' and since the name ...
    (comp.unix.programmer)