Skip to main content

Timeline for Implementing realloc in C

Current License: CC BY-SA 3.0

6 events
when toggle format what by license comment
Jan 24, 2017 at 11:25 comment added gnasher729 As an example, MacOS X and iOS have an implementation that rounds up the size to the next multiple of 16 and returns a block of that size, without any overhead and no metadata stored near the block.
Jan 24, 2017 at 7:22 history edited Phrancis CC BY-SA 3.0
added 20 characters in body
Dec 31, 2016 at 10:46 comment added Neil I just checked chapter 8 of K&R and their implementation of malloc DOES use this trick, but their meta-data is a pointer (to the next block in the chain) and an unsigned (size of the block). ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf
Dec 31, 2016 at 10:39 comment added Neil Who said anything about portable? Notice, I said 'might' allocate. Of course the C specification doesn't specify this particular trick, but many implementations DO use this idea to include memory allocation meta-data. For example, the debug build of Microsoft's malloc includes things like, which file/line allocated the memory, so if you forget to free it, at program exit, it will list all the code that have hanging allocations. A particular library will implement it in it's own way, the only portable bit is the interface.
Dec 31, 2016 at 6:04 comment added chux The metadata is not a portable solution. C does not specify that "the library will subtract 4 bytes from the pointer passed in".
Dec 28, 2016 at 12:15 history answered Neil CC BY-SA 3.0