Re: sizeof([ALLOCATED MEMORY])



Not necessarily. Consider the hypothetical "one time use"
allocater. realloc need only allocate a new chunk of the
appropriate size and copy the old over. It doesn't need to know
the size of the old, even for the copying if it can detect 'the
end' by some other means, analogous to encountering EOF.

For the extended malloc interface we should see how malloc is
implemented to see if size information is there and is fast to obtain.

I don't know any malloc implementation that does not store the size. So
if the size is there in all known implementations, it's logical to
propose new functions. If all known malloc implementations (check every
C library out there to check this) store the size, I think that we
should use that information to get better performance and less memory
use.

Maybe obtaining the size is not constant time in the "one time use"
allocator and you must do something similar to "strlen()", but let's be
practical: there is not such allocator in the real world, and I doubt
it will ever exist.

So let's asume that the size information is there and is very cheap to
obtain. Now we can discuss if proposed functions improve performance or
not, or they are useful enough enough to include them in the standard.
I can understand that you can think that those advanced reallocation
functions are not useful because you might never need them for general
purpose C programming. I think that memory reallocation is a common
pattern for a lot of C programs, and that there is an easy way to
improve their performance through these functions.

Regards,

Ion

.



Relevant Pages

  • Re: How to force fscanf to find only data on a single input line?
    ... Malcolm McLean wrote: ... Possibly each reallocation takes a little longer, depending on the ... allocator out there where it changes the number of reallocations, ...
    (comp.lang.c)
  • Re: sizeof([ALLOCATED MEMORY])
    ... I don't know any malloc implementation that does not store the size. ... If all known malloc implementations (check every ... the size of the allocated block is trivially easy to discover -- it's usually a few bytes before the address mallocor realloc() returns. ... allocator and you must do something similar to "strlen", ...
    (comp.lang.c)