/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Factory for native buffers.
*/
class NativeBuffers {
private NativeBuffers() { }
new ThreadLocal<NativeBuffer[]>();
/**
* Allocates a native buffer, of at least the given size, from the heap.
*/
// Make a new one of at least 2k
return new NativeBuffer(size);
}
/**
* Returns a native buffer, of at least the given size, from the thread
* local cache.
*/
// return from cache if possible
for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) {
return buffer;
}
}
}
return null;
}
/**
* Returns a native buffer, of at least the given size. The native buffer
* is taken from the thread local cache if possible; otherwise it is
* allocated from the heap.
*/
return buffer;
} else {
return allocNativeBuffer(size);
}
}
/**
* Releases the given buffer. If there is space in the thread local cache
* then the buffer goes into the cache; otherwise the memory is deallocated.
*/
// create cache if it doesn't exist
return;
}
// Put it in an empty slot if such exists
for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) {
return;
}
}
// Otherwise replace a smaller one in the cache if such exists
for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) {
return;
}
}
// free it
}
/**
* Copies a byte array and zero terminator into a given native buffer.
*/
}
/**
* Copies a byte array and zero terminator into a native buffer, returning
* the buffer.
*/
return buffer;
}
}