2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 ANSI C function realloc().
9 #include <proto/exec.h>
11 /*****************************************************************************
14 #include <sys/types.h>
24 Change the size of an allocated part of memory. The memory must
25 have been allocated by malloc() or calloc(). If you reduce the
26 size, the old contents will be lost. If you enlarge the size,
27 the new contents will be undefined.
30 oldmen - What you got from malloc() or calloc().
34 A pointer to the allocated memory or NULL. If you don't need the
35 memory anymore, you can pass this pointer to free(). If you don't,
36 the memory will be freed for you when the application exits.
39 If you get NULL, the memory at oldmem will not have been freed and
42 This function must not be used in a shared library or
43 in a threaded application.
51 free(), malloc(), calloc()
55 ******************************************************************************/
57 UBYTE
* mem
, * newmem
;
63 mem
= (UBYTE
*)oldmem
- AROS_ALIGN(sizeof(size_t));
64 oldsize
= *((size_t *)mem
);
66 /* Reduce or enlarge the memory ? */
69 /* Don't change anything for small changes */
70 if ((oldsize
- size
) < 4096)
75 else if (size
== oldsize
) /* Keep the size ? */
80 newmem
= malloc (size
);
84 CopyMem (oldmem
, newmem
, size
);