Home | History | Annotate | Download | only in memory
      1 // Copyright 2014 The Android Open Source Project
      2 //
      3 // This software is licensed under the terms of the GNU General Public
      4 // License version 2, as published by the Free Software Foundation, and
      5 // may be copied, distributed, and modified under those terms.
      6 //
      7 // This program is distributed in the hope that it will be useful,
      8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 // GNU General Public License for more details.
     11 
     12 #ifndef ANDROID_BASE_MEMORY_MALLOC_USABLE_SIZE_H
     13 #define ANDROID_BASE_MEMORY_MALLOC_USABLE_SIZE_H
     14 
     15 // Define HAVE_MALLOC_USABLE_SIZE to 1 to indicate that the current
     16 // system has malloc_usable_size(). Which takes the address of a malloc-ed
     17 // pointer, and return the size of the underlying storage block.
     18 // This is useful to optimize heap memory usage.
     19 
     20 // Including at least one C library header is required to define symbols
     21 // like __GLIBC__. Choose carefully because some headers like <stddef.h>
     22 // are actually provided by the compiler, not the C library and do not
     23 // define the macros we need.
     24 #include <stdint.h>
     25 
     26 #if defined(__GLIBC__)
     27 #  include <malloc.h>
     28 #  define USE_MALLOC_USABLE_SIZE  1
     29 #elif defined(__APPLE__) || defined(__FreeBSD__)
     30 #  include <malloc/malloc.h>
     31 #  define malloc_usable_size  malloc_size
     32 #  define USE_MALLOC_USABLE_SIZE  1
     33 #else
     34 #  define USE_MALLOC_USABLE_SIZE  0
     35 #endif
     36 
     37 #endif  // ANDROID_BASE_MEMORY_MALLOC_USABLE_SIZE_H
     38