diff options
author | Michael Brown <mcb30@etherboot.org> | 2007-01-18 12:54:18 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2007-01-18 12:54:18 +0000 |
commit | 35776f481c02caa700369db0e884bd9f7c7d3c0e (patch) | |
tree | 1deb52c624ab9bf9c56f5c26520d198a29e228f0 /src | |
parent | 06630a3036bc1a42696ba7f29235e75eddb4d562 (diff) | |
download | ipxe-35776f481c02caa700369db0e884bd9f7c7d3c0e.zip ipxe-35776f481c02caa700369db0e884bd9f7c7d3c0e.tar.gz ipxe-35776f481c02caa700369db0e884bd9f7c7d3c0e.tar.bz2 |
Don't always zero memory in malloc(). This saves around 2us on a
full-length PKB allocation.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/malloc.c | 19 | ||||
-rw-r--r-- | src/include/stdlib.h | 10 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/core/malloc.c b/src/core/malloc.c index bb34db3..db2b500 100644 --- a/src/core/malloc.c +++ b/src/core/malloc.c @@ -134,8 +134,6 @@ void * alloc_memblock ( size_t size, size_t align ) { */ if ( pre_size < MIN_MEMBLOCK_SIZE ) list_del ( &pre->list ); - /* Zero allocated memory, for calloc() */ - memset ( block, 0, size ); DBG ( "Allocated [%p,%p)\n", block, ( ( ( void * ) block ) + size ) ); return block; @@ -298,6 +296,23 @@ void free ( void *ptr ) { } /** + * Allocate cleared memory + * + * @v size Requested size + * @ret ptr Allocated memory + * + * Allocate memory as per malloc(), and zero it. + */ +void * _calloc ( size_t size ) { + void *data; + + data = malloc ( size ); + if ( data ) + memset ( data, 0, size ); + return data; +} + +/** * Add memory to allocation pool * * @v start Start address diff --git a/src/include/stdlib.h b/src/include/stdlib.h index 2b6471e..39ad831 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -8,6 +8,8 @@ extern void free ( void *ptr ); extern int system ( const char *command ); extern long int random ( void ); +extern void * _calloc ( size_t len ); + /** * Allocate cleared memory * @@ -17,12 +19,12 @@ extern long int random ( void ); * * Allocate memory as per malloc(), and zero it. * - * Note that malloc() and calloc() are identical, in the interests of - * reducing code size. Callers should not, however, rely on malloc() - * clearing memory, since this behaviour may change in future. + * This is implemented as a static inline, with the body of the + * function in _calloc(), since in most cases @c nmemb will be 1 and + * doing the multiply is just wasteful. */ static inline void * calloc ( size_t nmemb, size_t size ) { - return malloc ( nmemb * size ); + return _calloc ( nmemb * size ); } #endif /* STDLIB_H */ |