/** * @param capacity capacity in bytes */ BasicPageCache(int capacity, int pageSize) { int entryCount = entryCountFor(capacity, pageSize); mPageSize = pageSize; mHashTable = new int[entryCount]; acquireExclusive(); mNodesByteBuffer = ByteBuffer .allocateDirect(entryCount * (NODE_SIZE_IN_INTS * 4)) .order(ByteOrder.nativeOrder()); mNodes = mNodesByteBuffer.asIntBuffer(); mData = ByteBuffer.allocateDirect(entryCount * pageSize); // Initalize the nodes, all linked together. int ptr = 0; for (; ptr < entryCount * NODE_SIZE_IN_INTS; ptr += NODE_SIZE_IN_INTS) { mNodes.put(ptr + LESS_RECENT_PTR_FIELD, ptr - NODE_SIZE_IN_INTS); mNodes.put(ptr + MORE_RECENT_PTR_FIELD, ptr + NODE_SIZE_IN_INTS); mNodes.put(ptr + CHAIN_NEXT_PTR_FIELD, UNUSED_NODE); } mLeastRecentPtr = 0; mMostRecentPtr = ptr - NODE_SIZE_IN_INTS; for (int i=0; i<mHashTable.length; i++) { mHashTable[i] = NO_NEXT_ENTRY; } releaseExclusive(); }
/** * @param capacity capacity in bytes */ BasicPageCache(int capacity, int pageSize) { int entryCount = entryCountFor(capacity, pageSize); mPageSize = pageSize; mHashTable = new int[entryCount]; acquireExclusive(); mNodesByteBuffer = ByteBuffer .allocateDirect(entryCount * (NODE_SIZE_IN_INTS * 4)) .order(ByteOrder.nativeOrder()); mNodes = mNodesByteBuffer.asIntBuffer(); mData = ByteBuffer.allocateDirect(entryCount * pageSize); // Initialize the nodes, all linked together. int ptr = 0; for (; ptr < entryCount * NODE_SIZE_IN_INTS; ptr += NODE_SIZE_IN_INTS) { mNodes.put(ptr + LESS_RECENT_PTR_FIELD, ptr - NODE_SIZE_IN_INTS); mNodes.put(ptr + MORE_RECENT_PTR_FIELD, ptr + NODE_SIZE_IN_INTS); mNodes.put(ptr + CHAIN_NEXT_PTR_FIELD, UNUSED_NODE); } mLeastRecentPtr = 0; mMostRecentPtr = ptr - NODE_SIZE_IN_INTS; for (int i=0; i<mHashTable.length; i++) { mHashTable[i] = NO_NEXT_ENTRY; } releaseExclusive(); }
/** * @param capacity capacity in bytes */ BasicPageCache(int capacity, int pageSize) { int entryCount = entryCountFor(capacity, pageSize); mPageSize = pageSize; mHashTable = new int[entryCount]; acquireExclusive(); mNodesByteBuffer = ByteBuffer .allocateDirect(entryCount * (NODE_SIZE_IN_INTS * 4)) .order(ByteOrder.nativeOrder()); mNodes = mNodesByteBuffer.asIntBuffer(); mData = ByteBuffer.allocateDirect(entryCount * pageSize); // Initalize the nodes, all linked together. int ptr = 0; for (; ptr < entryCount * NODE_SIZE_IN_INTS; ptr += NODE_SIZE_IN_INTS) { mNodes.put(ptr + LESS_RECENT_PTR_FIELD, ptr - NODE_SIZE_IN_INTS); mNodes.put(ptr + MORE_RECENT_PTR_FIELD, ptr + NODE_SIZE_IN_INTS); mNodes.put(ptr + CHAIN_NEXT_PTR_FIELD, UNUSED_NODE); } mLeastRecentPtr = 0; mMostRecentPtr = ptr - NODE_SIZE_IN_INTS; for (int i=0; i<mHashTable.length; i++) { mHashTable[i] = NO_NEXT_ENTRY; } releaseExclusive(); }