<commit_before>/*
 * Copyright LWJGL. All rights reserved.
 * License terms: http://lwjgl.org/license.php
 */
package org.lwjgl.system;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryAccess.MemoryAccessor;

import java.nio.*;

import static org.lwjgl.Pointer.*;

/**
 * This class provides functionality for managing native memory.
 *
 * <p>All methods in this class will make use of {@link sun.misc.Unsafe} if it's available, for performance. If Unsafe is not available, the fallback
 * implementations make use of reflection and, in the worst-case, JNI.</p>
 *
 * <p>Method names in this class are prefixed with {@code mem} to avoid ambiguities when used with static imports.</p>
 */
public final class MemoryUtil {

	/** Alias for the null pointer address. */
	public static final long NULL = 0L;

	private static final MemoryAccessor ACCESSOR;

	/** The memory page size, in bytes. This value is always a power-of-two. */
	public static final int PAGE_SIZE;

	/** The cache-line size, in bytes. This value is always a power-of-two. */
	public static final int CACHE_LINE_SIZE;

	static {
		LWJGLUtil.initialize();

		ACCESSOR = MemoryAccess.getInstance();
		PAGE_SIZE = ACCESSOR.getPageSize();
		CACHE_LINE_SIZE = ACCESSOR.getCacheLineSize();

		LWJGLUtil.log("MemoryUtil MemoryAccessor: " + ACCESSOR.getClass().getSimpleName());
	}

	private MemoryUtil() {
	}

	/**
	 * The standard C malloc function.
	 *<commit_msg>Add javadoc note on text encoding/decoding<commit_after>/*
 * Copyright LWJGL. All rights reserved.
 * License terms: http://lwjgl.org/license.php
 */
package org.lwjgl.system;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryAccess.MemoryAccessor;

import java.nio.*;

import static org.lwjgl.Pointer.*;

/**
 * This class provides functionality for managing native memory.
 *
 * <p>All methods in this class will make use of {@link sun.misc.Unsafe} if it's available, for performance. If Unsafe is not available, the fallback
 * implementations make use of reflection and, in the worst-case, JNI.</p>
 *
 * <p>Method names in this class are prefixed with {@code mem} to avoid ambiguities when used with static imports.</p>
 *
 * <h3>Text encoding/decoding</h3>
 *
 * Three codecs are available, each with a different postfix:
 * <ul>
 * <li>UTF16 - Direct mapping of 2 bytes to Java char and vice versa</li>
 * <li>UTF8 - custom UTF-8 codec without intermediate allocations</li>
 * <li>ASCII - Not the original 7bit ASCII, but any character set with a single byte encoding (ISO 8859-1, Windows-1252, etc.)</li>
 * </ul>
 *
 * <p>Methods in bindings that accept/return {@code CharSequence}/{@code String} also support {@code ByteBuffer}, so custom codecs can be used if necessary.</p>
 */
public final class MemoryUtil {

	/** Alias for the null pointer address. */
	public static final long NULL = 0L;

	private static final MemoryAccessor ACCESSOR;

	/** The memory page size, in bytes. This value is always a power-of-two. */
	public static final int PAGE_SIZE;

	/** The cache-line size, in bytes. This value is always a power-of-two. */
	public static final int CACHE_LINE_SIZE;

	static {
		LWJGLUtil.initialize();

		ACCESSOR = MemoryAccess.getInstance();
		PAGE_SIZE = ACCESSOR.getPageSize();
		CACHE_LINE_SIZE = ACCESSOR.getCacheLineSize();

		LWJGLUtil.log("MemoryUtil MemoryAccessor: " + ACCESSOR.getClass().getSimpleName());
	}

	private MemoryUtil() {
	}

	/**
	 * The standard C malloc function.
	 *
{'fraction_non_alphanumeric': 0.10943606923506422, 'fraction_numerical': 0.00530429927414852, 'mean_word_length': 4.032303370786517, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1460551', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1089, 'n_words': 386}