[RFC] how to get the size of a malloc(9) block ?

jb jb.1234abcd at gmail.com
Sat Nov 30 21:43:18 UTC 2013


 <dt71 <at> gmx.com> writes:

> ... 
> So new flags could be [1]:
> - realloc_flags(p, s, REALLOCF_NO_MOVE): Resize object p, without moving 
> it, to size s. With this restriction, when requesting more memory, and
> the specified amount isn't available, don't do anything (when requesting
> less memory, always succeed).
> - realloc_flags(p, s, REALLOCF_NO_MOVE | REALLOCF_ELASTIC): Resize object
> p, without moving it, to size s. With this restriction, when requesting
> more memory, and the specified amount isn't available, reserve as much as
> possible (when requesting less memory, always succeed).
> ...

The realloc_flags(), having different behavior from realloc(), should state
what happens if:

  If the pointer is a null pointer, the function does not change anything.

  If the new size is zero, the function does not change anything.

  If the new size is the same as the old size, the function does not change
  anything.

The return values have to be reviewed also.
The function returns: 
- a pointer to the object specifid on entry
- a null pointer if the object could not be modified 
- a null pointer if there was insufficient free memory available to extend 
  the size of the object

Reference to realloc():
http://www.cplusplus.com/reference/cstdlib/realloc/

jb




More information about the freebsd-current mailing list