AVPKit
com::avpkit::ferry::JNIMemoryManager Class Reference

This class's implementation of malloc() and free() will forward to the standard library's malloc() and free(), UNLESS you're running in a JVM, in which case it will use Java to manage the memory for us. More...

#include <JNIMemoryManager.h>

Static Public Member Functions

static void * malloc (size_t requested_size)
 Create a malloced block of AT LEAST site_t bounds long. More...
 
static void free (void *mem)
 Free memory previously allocated by malloc(void*, size_t). More...
 
static void * malloc (void *allocator, size_t requested_size)
 Create a malloced block of AT LEAST site_t bounds long by using an allocator. More...
 

Detailed Description

This class's implementation of malloc() and free() will forward to the standard library's malloc() and free(), UNLESS you're running in a JVM, in which case it will use Java to manage the memory for us.

Use it when you have large memory structures that live for a long time that you want the JVM to resource manage for you, or if you're trying to track down an object in Java that is collecting large objects; this will allow you to tie back big chunks of memory to the misbehaving java object in your code (using a memory profiler like SAP's Eclipse plugin).

Definition at line 49 of file JNIMemoryManager.h.

Member Function Documentation

◆ free()

void com::avpkit::ferry::JNIMemoryManager::free ( void *  mem)
static

Free memory previously allocated by malloc(void*, size_t).

Parameters
mempreviously allocated by malloc(void*, size_t)

Definition at line 102 of file JNIMemoryManager.cpp.

103 {
104  VSJNI_free(mem);
105 }

◆ malloc() [1/2]

void * com::avpkit::ferry::JNIMemoryManager::malloc ( size_t  requested_size)
static

Create a malloced block of AT LEAST site_t bounds long.

This block will be aligned on a 128-bit boundary, suitable for passing to libraries that do SSE-based operations on it.

Parameters
requested_sizeRequested minimum size of memory, in bytes
Exceptions
std::std_allocIf memory cannot be allocated
Returns
a block of memory of at least requested size aligned on a 128-bit boundary.

Definition at line 89 of file JNIMemoryManager.cpp.

90 {
91  return JNIMemoryManager::malloc(0, requested_size);
92 }
static void * malloc(size_t requested_size)
Create a malloced block of AT LEAST site_t bounds long.

◆ malloc() [2/2]

void * com::avpkit::ferry::JNIMemoryManager::malloc ( void *  allocator,
size_t  requested_size 
)
static

Create a malloced block of AT LEAST site_t bounds long by using an allocator.

Allocates a block of memory using the passed in allocator. If running inside a JVM, allocator must be a jobject, and must be a subclass of com.avpkit.ferry.JNIMemoryManager. Also you must ensure that allocator lives longer than the block of memory you allocate (i.e. does not get collected by the GC).

This method is useful for Swig proxy objects where you want to fake a reference from the proxy object to memory allocated by the object the proxy objet mallocs. Then, when checked using profiling tools, the native memory will accumulate to the proxy object, which will help you find proxy leaks.

If you are not allocating with the JVM, or we are using JVM Direct Buffers for memory, the allocator object is only used to help print debugging messages.

This block will be aligned on a 128-bit boundary, suitable for passing to libraries that do SSE-based operations on it.

Lastly if you understood or followed any of the above comments you're not drunk enough to work on this code.

Parameters
requested_sizeRequested minimum size of memory, in bytes
allocatorEither a jobject as documented above, or 0.
Exceptions
std::std_allocIf memory cannot be allocated

Definition at line 95 of file JNIMemoryManager.cpp.

96 {
97  void * retval = VSJNI_malloc(static_cast<jobject> (obj), requested_size);
98  return retval;
99 }

The documentation for this class was generated from the following files: