Size of malloc'd?



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?

.



Relevant Pages

  • 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 VS and memcpy...
    ... memcpy(buffer, header, sizeof header); ... John Carson ha scritto: ... Where "yqhsfjkvdfdsfhfe" ius the content of the buffer, ...
    (microsoft.public.vc.language)
  • Re: sprintf confusion
    ... You can find out with sizeof. ... If you want a buffer big enough to support an integer parameter n, ... since decimal representation gives us ten digits ('0' through ...
    (comp.lang.c)
  • buffer size
    ... memcpy(pos, bytes, sizeof (size)); ... pos+= sizeof; ... char* pos = buffer; ... The problem is finding the size of se buffer after the serialization. ...
    (comp.lang.c)
  • Re: Are bad developer libraries the problem with M$ software?
    ... proper use of snprintf would be: ... size of a buffer, not the actual size of the buffer. ... sizeof will return the size of the data type passed to it. ...
    (SecProg)