org.apache.datasketches.memory.package-info Maven / Gradle / Ivy
Show all versions of datasketches-memory Show documentation
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* This package provides high performance primitive and primitive array access to direct (native),
* off-heap memory and memory-mapped file resources, and consistent views into
* {@link java.nio.ByteBuffer}, and on-heap primitive arrays. It can be used as a more
* comprehensive and flexible replacement for {@link java.nio.ByteBuffer}.
*
*
* In addition, this package provides:
*
* - Two different access APIs: read-only {@link org.apache.datasketches.memory.Memory} and
* {@link org.apache.datasketches.memory.WritableMemory} for absolute offset access,
* and read-only {@link org.apache.datasketches.memory.Buffer} and
* {@link org.apache.datasketches.memory.WritableBuffer}
* for relative positional access (similar to ByteBuffer).
*
* - Clean separation of Read-only API from Writable API, which makes writable versus read-only
* resources detectable at compile time.
*
* - The conversion from Writable to read-only is just a cast, so no unnecessary objects are
* created. For example:
*
* WritableMemory wMem = ...
* Memory mem = wMem;
*
*
*
* - {@link java.lang.AutoCloseable} for the external resources that require it,
* which enables compile-time checks for non-closed resources.
*
* - Immediate invalidation of all downstream references of an AutoCloseable
* resource when that resource is closed, either manually or by the JVM.
* This virtually eliminates the possibility of accidentally writing into the memory space
* previously owned by a closed resource.
*
* - Improved performance over the prior Memory implementation.
*
* - No external dependencies, which makes it simple to install in virtually any Java environment.
*
*
*
* More specifically, this package provides access to four different types of resources using
* two different access APIs. These resources are contiguous blobs of bytes that provide at least
* byte-level read and write access. The four resources are:
*
* - Direct (a.k.a. Native) off-heap memory allocated by the user.
* - Memory-mapped files, both writable and read-only.
* - {@code ByteBuffers}, both heap-based and direct, writable and read-only.
* - Heap-based primitive arrays, which can be accessed as writable or read-only.
*
*
* The two different access APIs are:
* - Memory, WritableMemory: Absolute offset addressing into a resource.
* - Buffer, WritableBuffer: Position relative addressing into a resource.
*
*
* In addition, all combinations of access APIs and backing resources can be accessed via
* multibyte primitive methods (e.g.
* getLong(...), getLongArray(...), putLong(...), putLongArray(...)) as either
* {@link java.nio.ByteOrder#BIG_ENDIAN} or {@link java.nio.ByteOrder#LITTLE_ENDIAN}.
*
* The resources don't know or care about the access APIs, and the access
* APIs don't really know or care what resource they are accessing.
*
* An access API is joined with a resource with a static factory method.
*
*
Moving back and forth between Memory and Buffer:
*
* Memory mem = ...
* Buffer buf = mem.asBuffer();
* ...
* Memory mem2 = buf.asMemory();
* ...
*
*
* Hierarchical memory regions can be easily created:
*
* WritableMemory wMem = ...
* WritableMemory wReg = wMem.writableRegion(offset, length); //OR
* Memory region = wMem.region(offset, length);
*
*
* @author Lee Rhodes
*/
package org.apache.datasketches.memory;