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

From: jb <jb.1234abcd_at_gmail.com>
Date: Sat, 30 Nov 2013 21:42:49 +0000 (UTC)
 <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
Received on Sat Nov 30 2013 - 20:43:18 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:44 UTC