[uClibc-cvs] uClibc/libc/stdlib/malloc-simple alloc.c,1.12,1.13
Erik Andersen
andersen at uclibc.org
Tue Dec 30 10:40:51 UTC 2003
- Previous message: [uClibc-cvs] uClibc/libc/stdlib/malloc-930716 Makefile, 1.11, NONE README, 1.1, NONE malloc.c, 1.14, NONE malloc.h, 1.3, NONE memalign.c, 1.4, NONE realloc.c, 1.5, NONE
- Next message: [uClibc-cvs] uClibc/libc/stdlib/malloc-standard Makefile, NONE, 1.1 calloc.c, NONE, 1.1 free.c, NONE, 1.1 mallinfo.c, NONE, 1.1 malloc.c, NONE, 1.1 malloc.h, NONE, 1.1 mallopt.c, NONE, 1.1 memalign.c, NONE, 1.1 realloc.c, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /var/cvs/uClibc/libc/stdlib/malloc-simple
In directory nail:/tmp/cvs-serv5823/libc/stdlib/malloc-simple
Modified Files:
alloc.c
Log Message:
Rework malloc. The new default implementation is based on dlmalloc from Doug
Lea. It is about 2x faster than the old malloc-930716, and behave itself much
better -- it will properly release memory back to the system, and it uses a
combination of brk() for small allocations and mmap() for larger allocations.
-Erik
Index: alloc.c
===================================================================
RCS file: /var/cvs/uClibc/libc/stdlib/malloc-simple/alloc.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- alloc.c 30 Dec 2003 01:41:14 -0000 1.12
+++ alloc.c 30 Dec 2003 10:40:49 -0000 1.13
@@ -31,14 +31,14 @@
#ifdef __UCLIBC_HAS_MMU__
result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (result == MAP_FAILED)
return 0;
* (size_t *) result = size;
return(result + sizeof(size_t));
#else
result = mmap((void *) 0, size, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (result == MAP_FAILED)
return 0;
return(result);
@@ -47,12 +47,27 @@
#endif
#ifdef L_calloc
-void *calloc(size_t num, size_t size)
+void * calloc(size_t nmemb, size_t lsize)
{
- void *ptr = malloc(num * size);
- if (ptr)
- memset(ptr, 0, num * size);
- return ptr;
+ void *result;
+ size_t size=lsize * nmemb;
+
+ /* guard vs integer overflow, but allow nmemb
+ * to fall through and call malloc(0) */
+ if (nmemb && lsize != (size / nmemb)) {
+ __set_errno(ENOMEM);
+ return NULL;
+ }
+ result=malloc(size);
+#if 0
+ /* Standard unix mmap using /dev/zero clears memory so calloc
+ * doesn't need to actually zero anything....
+ */
+ if (result != NULL) {
+ memset(result, 0, size);
+ }
+#endif
+ return result;
}
#endif
- Previous message: [uClibc-cvs] uClibc/libc/stdlib/malloc-930716 Makefile, 1.11, NONE README, 1.1, NONE malloc.c, 1.14, NONE malloc.h, 1.3, NONE memalign.c, 1.4, NONE realloc.c, 1.5, NONE
- Next message: [uClibc-cvs] uClibc/libc/stdlib/malloc-standard Makefile, NONE, 1.1 calloc.c, NONE, 1.1 free.c, NONE, 1.1 mallinfo.c, NONE, 1.1 malloc.c, NONE, 1.1 malloc.h, NONE, 1.1 mallopt.c, NONE, 1.1 memalign.c, NONE, 1.1 realloc.c, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the uClibc-cvs
mailing list