2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 C99 function realloc().
9 #include <proto/exec.h>
11 /*****************************************************************************
23 Change the size of an allocated part of memory. The memory must
24 have been allocated by malloc() or calloc(). If you reduce the
25 size, the old contents will be lost. If you enlarge the size,
26 the new contents will be undefined.
29 oldmem - What you got from malloc() or calloc().
33 A pointer to the allocated memory or NULL. If you don't need the
34 memory anymore, you can pass this pointer to free(). If you don't,
35 the memory will be freed for you when the application exits.
38 If you get NULL, the memory at oldmem will not have been freed and
46 calloc(), free(), malloc()
50 ******************************************************************************/
52 UBYTE
* mem
, * newmem
;
58 mem
= (UBYTE
*)oldmem
- AROS_ALIGN(sizeof(size_t));
59 oldsize
= *((size_t *)mem
);
61 /* Reduce or enlarge the memory ? */
64 /* Don't change anything for small changes */
65 if ((oldsize
- size
) < 4096)
70 else if (size
== oldsize
) /* Keep the size ? */
75 newmem
= malloc (size
);
81 CopyMem (oldmem
, newmem
, size
);