am a2b32b34: Merge "Update malloc.h"
* commit 'a2b32b34220a1bdea566502da1e3254c90f62f16': Update malloc.h
This commit is contained in:
@@ -1,33 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
* All rights reserved.
|
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* modification, are permitted provided that the following conditions
|
* you may not use this file except in compliance with the License.
|
||||||
* are met:
|
* You may obtain a copy of the License at
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
*
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
* See the License for the specific language governing permissions and
|
||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
* limitations under the License.
|
||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
* SUCH DAMAGE.
|
|
||||||
*/
|
*/
|
||||||
#ifndef _MALLOC_H_
|
|
||||||
#define _MALLOC_H_
|
|
||||||
|
|
||||||
|
#ifndef LIBC_INCLUDE_MALLOC_H_
|
||||||
|
#define LIBC_INCLUDE_MALLOC_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Declaration of malloc routines. Bionic uses dlmalloc (see
|
||||||
|
* upstream-dlmalloc) but doesn't directly include it here to keep the
|
||||||
|
* defined malloc.h interface small.
|
||||||
|
*/
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -35,70 +29,33 @@ __BEGIN_DECLS
|
|||||||
|
|
||||||
extern __mallocfunc void* malloc(size_t);
|
extern __mallocfunc void* malloc(size_t);
|
||||||
extern __mallocfunc void* calloc(size_t, size_t);
|
extern __mallocfunc void* calloc(size_t, size_t);
|
||||||
extern __mallocfunc void* realloc(void *, size_t);
|
extern void* realloc(void *, size_t);
|
||||||
extern void free(void *);
|
extern void free(void *);
|
||||||
|
|
||||||
extern void* memalign(size_t alignment, size_t bytesize);
|
extern void* memalign(size_t alignment, size_t bytesize);
|
||||||
|
extern size_t malloc_usable_size(void*);
|
||||||
|
|
||||||
extern void* valloc(size_t bytesize);
|
extern void* valloc(size_t bytesize);
|
||||||
extern void* pvalloc(size_t bytesize);
|
extern void* pvalloc(size_t bytesize);
|
||||||
extern int mallopt(int param_number, int param_value);
|
|
||||||
extern size_t malloc_footprint(void);
|
|
||||||
extern size_t malloc_max_footprint(void);
|
|
||||||
|
|
||||||
|
#ifndef STRUCT_MALLINFO_DECLARED
|
||||||
|
#define STRUCT_MALLINFO_DECLARED 1
|
||||||
struct mallinfo {
|
struct mallinfo {
|
||||||
size_t arena; /* non-mmapped space allocated from system */
|
size_t arena;
|
||||||
size_t ordblks; /* number of free chunks */
|
size_t ordblks;
|
||||||
size_t smblks; /* always 0 */
|
size_t smblks;
|
||||||
size_t hblks; /* always 0 */
|
size_t hblks;
|
||||||
size_t hblkhd; /* space in mmapped regions */
|
size_t hblkhd;
|
||||||
size_t usmblks; /* maximum total allocated space */
|
size_t usmblks;
|
||||||
size_t fsmblks; /* always 0 */
|
size_t fsmblks;
|
||||||
size_t uordblks; /* total allocated space */
|
size_t uordblks;
|
||||||
size_t fordblks; /* total free space */
|
size_t fordblks;
|
||||||
size_t keepcost; /* releasable (via malloc_trim) space */
|
size_t keepcost;
|
||||||
};
|
};
|
||||||
|
#endif /* STRUCT_MALLINFO_DECLARED */
|
||||||
|
|
||||||
extern struct mallinfo mallinfo(void);
|
extern struct mallinfo mallinfo(void);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
malloc_usable_size(void* p);
|
|
||||||
|
|
||||||
Returns the number of bytes you can actually use in
|
|
||||||
an allocated chunk, which may be more than you requested (although
|
|
||||||
often not) due to alignment and minimum size constraints.
|
|
||||||
You can use this many bytes without worrying about
|
|
||||||
overwriting other allocated objects. This is not a particularly great
|
|
||||||
programming practice. malloc_usable_size can be more useful in
|
|
||||||
debugging and assertions, for example:
|
|
||||||
|
|
||||||
p = malloc(n);
|
|
||||||
assert(malloc_usable_size(p) >= 256);
|
|
||||||
*/
|
|
||||||
extern size_t malloc_usable_size(void* block);
|
|
||||||
|
|
||||||
/*
|
|
||||||
malloc_stats();
|
|
||||||
Prints on stderr the amount of space obtained from the system (both
|
|
||||||
via sbrk and mmap), the maximum amount (which may be more than
|
|
||||||
current if malloc_trim and/or munmap got called), and the current
|
|
||||||
number of bytes allocated via malloc (or realloc, etc) but not yet
|
|
||||||
freed. Note that this is the number of bytes allocated, not the
|
|
||||||
number requested. It will be larger than the number requested
|
|
||||||
because of alignment and bookkeeping overhead. Because it includes
|
|
||||||
alignment wastage as being in use, this figure may be greater than
|
|
||||||
zero even when no user-level chunks are allocated.
|
|
||||||
|
|
||||||
The reported current and maximum system memory can be inaccurate if
|
|
||||||
a program makes other calls to system memory allocation functions
|
|
||||||
(normally sbrk) outside of malloc.
|
|
||||||
|
|
||||||
malloc_stats prints only the most commonly interesting statistics.
|
|
||||||
More information can be obtained by calling mallinfo.
|
|
||||||
*/
|
|
||||||
extern void malloc_stats(void);
|
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#endif /* _MALLOC_H_ */
|
#endif /* LIBC_INCLUDE_MALLOC_H_ */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user