mirror of https://github.com/ipxe/ipxe.git
Don't always zero memory in malloc(). This saves around 2us on a
full-length PKB allocation.pull/1/head
parent
06630a3036
commit
35776f481c
|
@ -134,8 +134,6 @@ void * alloc_memblock ( size_t size, size_t align ) {
|
||||||
*/
|
*/
|
||||||
if ( pre_size < MIN_MEMBLOCK_SIZE )
|
if ( pre_size < MIN_MEMBLOCK_SIZE )
|
||||||
list_del ( &pre->list );
|
list_del ( &pre->list );
|
||||||
/* Zero allocated memory, for calloc() */
|
|
||||||
memset ( block, 0, size );
|
|
||||||
DBG ( "Allocated [%p,%p)\n", block,
|
DBG ( "Allocated [%p,%p)\n", block,
|
||||||
( ( ( void * ) block ) + size ) );
|
( ( ( void * ) block ) + size ) );
|
||||||
return block;
|
return block;
|
||||||
|
@ -297,6 +295,23 @@ void free ( void *ptr ) {
|
||||||
realloc ( ptr, 0 );
|
realloc ( ptr, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Add memory to allocation pool
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,6 +8,8 @@ extern void free ( void *ptr );
|
||||||
extern int system ( const char *command );
|
extern int system ( const char *command );
|
||||||
extern long int random ( void );
|
extern long int random ( void );
|
||||||
|
|
||||||
|
extern void * _calloc ( size_t len );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate cleared memory
|
* Allocate cleared memory
|
||||||
*
|
*
|
||||||
|
@ -17,12 +19,12 @@ extern long int random ( void );
|
||||||
*
|
*
|
||||||
* Allocate memory as per malloc(), and zero it.
|
* Allocate memory as per malloc(), and zero it.
|
||||||
*
|
*
|
||||||
* Note that malloc() and calloc() are identical, in the interests of
|
* This is implemented as a static inline, with the body of the
|
||||||
* reducing code size. Callers should not, however, rely on malloc()
|
* function in _calloc(), since in most cases @c nmemb will be 1 and
|
||||||
* clearing memory, since this behaviour may change in future.
|
* doing the multiply is just wasteful.
|
||||||
*/
|
*/
|
||||||
static inline void * calloc ( size_t nmemb, size_t size ) {
|
static inline void * calloc ( size_t nmemb, size_t size ) {
|
||||||
return malloc ( nmemb * size );
|
return _calloc ( nmemb * size );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* STDLIB_H */
|
#endif /* STDLIB_H */
|
||||||
|
|
Loading…
Reference in New Issue