Class RPmalloc

  • public class RPmalloc
    extends java.lang.Object
    Native bindings to the rpmalloc library. rpmalloc is a public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C.

    You are required to call these functions from your own code in order to initialize and finalize the allocator in your process and threads:

    Then simply use the malloc/free and the other malloc style replacement functions. Remember all allocations are 16-byte aligned, so no need to call the explicit memalign/aligned_alloc/posix_memalign functions unless you need greater alignment, they are simply wrappers to make it easier to replace in existing code.

    • Method Detail

      • nrpmalloc_initialize

        public static int nrpmalloc_initialize()
        Unsafe version of: malloc_initialize
      • rpmalloc_initialize

        public static boolean rpmalloc_initialize()
        Initializes allocator with default configuration.
      • nrpmalloc_initialize_config

        public static int nrpmalloc_initialize_config​(long config)
        Unsafe version of: malloc_initialize_config
      • rpmalloc_initialize_config

        public static boolean rpmalloc_initialize_config​(@Nullable
                                                         RPMallocConfig config)
        Initializes allocator with given configuration.
        config - an optional RPMallocConfig instance
      • nrpmalloc_config

        public static long nrpmalloc_config()
        Unsafe version of: malloc_config
      • rpmalloc_config

        public static RPMallocConfig rpmalloc_config()
        Gets allocator configuration.
      • rpmalloc_finalize

        public static void rpmalloc_finalize()
        Finalizes allocator.
      • rpmalloc_thread_initialize

        public static void rpmalloc_thread_initialize()
        Initializes allocator for calling thread.
      • rpmalloc_thread_finalize

        public static void rpmalloc_thread_finalize()
        Finalizes allocator for calling thread.
      • rpmalloc_thread_collect

        public static void rpmalloc_thread_collect()
        Performs deferred deallocations pending for the calling thread heap.
      • rpmalloc_is_thread_initialized

        public static boolean rpmalloc_is_thread_initialized()
        Query if allocator is initialized for calling thread.
      • nrpmalloc_thread_statistics

        public static void nrpmalloc_thread_statistics​(long stats)
        Unsafe version of: malloc_thread_statistics
      • rpmalloc_thread_statistics

        public static void rpmalloc_thread_statistics​(RPmallocThreadStatistics stats)
        Gets per-thread statistics.
      • nrpmalloc_global_statistics

        public static void nrpmalloc_global_statistics​(long stats)
        Unsafe version of: malloc_global_statistics
      • rpmalloc_global_statistics

        public static void rpmalloc_global_statistics​(RPmallocGlobalStatistics stats)
        Gets global statistics.
      • nrpmalloc

        public static long nrpmalloc​(long size)
        Unsafe version of: malloc
      • rpmalloc

        public static java.nio.ByteBuffer rpmalloc​(long size)
        Allocates a memory block of at least the given size.
      • nrpfree

        public static void nrpfree​(long ptr)
        Unsafe version of: free
      • rpfree

        public static void rpfree​(@Nullable
                                  java.nio.ByteBuffer ptr)
        public static void rpfree​(@Nullable
                                  java.nio.ShortBuffer ptr)
        public static void rpfree​(@Nullable
                                  java.nio.IntBuffer ptr)
        public static void rpfree​(@Nullable
                                  java.nio.LongBuffer ptr)
        public static void rpfree​(@Nullable
                                  java.nio.FloatBuffer ptr)
        public static void rpfree​(@Nullable
                                  java.nio.DoubleBuffer ptr)
        public static void rpfree​(@Nullable
                                  PointerBuffer ptr)
        Frees the given memory block.
      • nrpcalloc

        public static long nrpcalloc​(long num,
                                     long size)
        Unsafe version of: calloc
      • rpcalloc

        public static java.nio.ByteBuffer rpcalloc​(long num,
                                                   long size)
        Allocates a memory block of at least the given size and zero initializes it.
      • nrprealloc

        public static long nrprealloc​(long ptr,
                                      long size)
        Unsafe version of: realloc
      • rprealloc

        public static java.nio.ByteBuffer rprealloc​(@Nullable
                                                    java.nio.ByteBuffer ptr,
                                                    long size)
        Reallocates the given block to at least the given size.
      • nrpaligned_realloc

        public static long nrpaligned_realloc​(long ptr,
                                              long alignment,
                                              long size,
                                              long oldsize,
                                              int flags)
        Unsafe version of: aligned_realloc
      • rpaligned_realloc

        public static java.nio.ByteBuffer rpaligned_realloc​(@Nullable
                                                            java.nio.ByteBuffer ptr,
                                                            long alignment,
                                                            long size,
                                                            int flags)
        Reallocates the given block to at least the given size and alignment, with optional control flags (see MALLOC_NO_PRESERVE)
      • nrpaligned_alloc

        public static long nrpaligned_alloc​(long alignment,
                                            long size)
        Unsafe version of: aligned_alloc
      • rpaligned_alloc

        public static java.nio.ByteBuffer rpaligned_alloc​(long alignment,
                                                          long size)
        Allocates a memory block of at least the given size and alignment.
      • nrpmemalign

        public static long nrpmemalign​(long alignment,
                                       long size)
        Unsafe version of: memalign
      • rpmemalign

        public static java.nio.ByteBuffer rpmemalign​(long alignment,
                                                     long size)
        Allocates a memory block of at least the given size and alignment.
      • nrpposix_memalign

        public static int nrpposix_memalign​(long memptr,
                                            long alignment,
                                            long size)
        Unsafe version of: posix_memalign
      • rpposix_memalign

        public static int rpposix_memalign​(PointerBuffer memptr,
                                           long alignment,
                                           long size)
        Allocates a memory block of at least the given size and alignment.
      • nrpmalloc_usable_size

        public static long nrpmalloc_usable_size​(long ptr)
        Unsafe version of: malloc_usable_size
      • rpmalloc_usable_size

        public static long rpmalloc_usable_size​(java.nio.ByteBuffer ptr)
        public static long rpmalloc_usable_size​(java.nio.ShortBuffer ptr)
        public static long rpmalloc_usable_size​(java.nio.IntBuffer ptr)
        public static long rpmalloc_usable_size​(java.nio.LongBuffer ptr)
        public static long rpmalloc_usable_size​(java.nio.FloatBuffer ptr)
        public static long rpmalloc_usable_size​(java.nio.DoubleBuffer ptr)
        public static long rpmalloc_usable_size​(PointerBuffer ptr)
        Queries the usable size of the given memory block (from given pointer to the end of block).